github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/preflight/testing/fake.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package testing 21 22 import ( 23 troubleshoot "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" 24 25 preflightv1beta2 "github.com/1aal/kubeblocks/externalapis/preflight/v1beta2" 26 ) 27 28 const ( 29 clusterVersion = ` 30 { 31 "info": { 32 "major": "1", 33 "minor": "23", 34 "gitVersion": "v1.23.15", 35 "gitCommit": "b84cb8ab29366daa1bba65bc67f54de2f6c34848", 36 "gitTreeState": "clean", 37 "buildDate": "2022-12-08T10:42:57Z", 38 "goVersion": "go1.17.13", 39 "compiler": "gc", 40 "platform": "linux/arm64" 41 }, 42 "string": "v1.23.15" 43 }` 44 deploymentStatus = ` 45 { 46 "string": "1" 47 }` 48 ) 49 50 func FakeAnalyzers() []*troubleshoot.Analyze { 51 return []*troubleshoot.Analyze{ 52 { 53 ClusterVersion: &troubleshoot.ClusterVersion{ 54 AnalyzeMeta: troubleshoot.AnalyzeMeta{ 55 CheckName: "ClusterVersionCheck", 56 }, 57 Outcomes: []*troubleshoot.Outcome{ 58 { 59 Pass: &troubleshoot.SingleOutcome{ 60 Message: "version is ok.", 61 }, 62 }, 63 }, 64 }, 65 }, 66 { 67 DeploymentStatus: &troubleshoot.DeploymentStatus{ 68 AnalyzeMeta: troubleshoot.AnalyzeMeta{ 69 CheckName: "DeploymentStatusCheck", 70 }, 71 Outcomes: []*troubleshoot.Outcome{ 72 { 73 Warn: &troubleshoot.SingleOutcome{ 74 When: "absent", 75 Message: "The deployment is not present.", 76 }, 77 Pass: &troubleshoot.SingleOutcome{ 78 Message: "There are multiple replicas of the deployment ready", 79 }, 80 }, 81 }, 82 }, 83 }, 84 } 85 } 86 87 func FakeCollectedData() map[string][]byte { 88 return map[string][]byte{ 89 "cluster-info/cluster_version.json": []byte(clusterVersion), 90 "cluster-info/deployment_status.json": []byte(deploymentStatus), 91 } 92 } 93 94 func FakeKbPreflight() *preflightv1beta2.Preflight { 95 var collectList []*troubleshoot.Collect 96 collect := &troubleshoot.Collect{ 97 ClusterInfo: &troubleshoot.ClusterInfo{}, 98 ClusterResources: &troubleshoot.ClusterResources{}, 99 } 100 collectList = append(collectList, collect) 101 102 return &preflightv1beta2.Preflight{ 103 Spec: preflightv1beta2.PreflightSpec{ 104 PreflightSpec: troubleshoot.PreflightSpec{ 105 Collectors: collectList, 106 }, 107 }, 108 } 109 } 110 111 func FakeKbHostPreflight() *preflightv1beta2.HostPreflight { 112 var extendCollectList []*preflightv1beta2.ExtendHostCollect 113 var remoteCollectList []*troubleshoot.RemoteCollect 114 extendCollectList = append( 115 extendCollectList, 116 &preflightv1beta2.ExtendHostCollect{HostUtility: &preflightv1beta2.HostUtility{}}, 117 ) 118 remoteCollectList = append(remoteCollectList, &troubleshoot.RemoteCollect{CPU: &troubleshoot.RemoteCPU{}}) 119 120 hostPreflight := &preflightv1beta2.HostPreflight{ 121 Spec: preflightv1beta2.HostPreflightSpec{ 122 ExtendCollectors: extendCollectList, 123 }, 124 } 125 hostPreflight.Spec.RemoteCollectors = remoteCollectList 126 return hostPreflight 127 }