github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/test/e2e/testdata/smoketest/config.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 smoketest 21 22 import ( 23 "log" 24 "os" 25 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 29 . "github.com/1aal/kubeblocks/test/e2e" 30 e2eutil "github.com/1aal/kubeblocks/test/e2e/util" 31 ) 32 33 func Config() { 34 BeforeEach(func() { 35 }) 36 37 AfterEach(func() { 38 }) 39 40 dir, err := os.Getwd() 41 if err != nil { 42 log.Println(err) 43 } 44 45 Context("Configure running e2e information", func() { 46 It("create a secret to save the access key and ", func() { 47 secret := "kubectl get secret " + ConfigType + "-credential-for-backuprepo -n kb-system | grep " + 48 ConfigType + "-credential-for-backuprepo | awk '{print $1}'" 49 if checkResourceExists(secret) { 50 log.Println("secret " + ConfigType + "-credential-for-backuprepo already exists") 51 } else { 52 var accessKey, secretKey string 53 if ConfigType == "s3" { 54 accessKey = e2eutil.ExecCommand("aws configure get aws_access_key_id") 55 secretKey = e2eutil.ExecCommand("aws configure get aws_secret_access_key") 56 } else { 57 accessKey = e2eutil.ExecCommand("aliyun configure get access_key_id") 58 secretKey = e2eutil.ExecCommand("aliyun configure get access_key_secret") 59 } 60 createSecret := "kubectl create secret generic " + ConfigType + "-credential-for-backuprepo \\\n" + 61 " -n kb-system \\\n" + 62 " --from-literal=accessKeyId=" + e2eutil.StringStrip(accessKey) + " \\\n" + 63 " --from-literal=secretAccessKey=" + e2eutil.StringStrip(secretKey) 64 b := e2eutil.ExecuteCommand(createSecret) 65 Expect(b).Should(BeTrue()) 66 } 67 }) 68 It(" configure backup-repo", func() { 69 repo := "kubectl get BackupRepo | grep my-repo | awk '{print $1}'" 70 if checkResourceExists(repo) { 71 log.Println("BackupRepo already exists") 72 } else { 73 var yaml string 74 if ConfigType == "oss" { 75 yaml = dir + "/testdata/config/backuprepo_oss.yaml" 76 } else { 77 yaml = dir + "/testdata/config/backuprepo_s3.yaml" 78 } 79 b := e2eutil.OpsYaml(yaml, "create") 80 Expect(b).Should(BeTrue()) 81 } 82 }) 83 It(" configure componentresourceconstraint custom", func() { 84 componentResourceConstraint := "kubectl get ComponentResourceConstraint | grep kb-resource-constraint-e2e | awk '{print $1}'" 85 if checkResourceExists(componentResourceConstraint) { 86 log.Println("ComponentResourceConstraint already exists") 87 } else { 88 b := e2eutil.OpsYaml(dir+"/testdata/config/componentresourceconstraint_custom.yaml", "create") 89 Expect(b).Should(BeTrue()) 90 } 91 }) 92 It(" configure custom class", func() { 93 componentClassDefinition := "kubectl get ComponentClassDefinition | grep custom-class | awk '{print $1}'" 94 if checkResourceExists(componentClassDefinition) { 95 log.Println("ComponentClassDefinition already exists") 96 } else { 97 b := e2eutil.OpsYaml(dir+"/testdata/config/custom_class.yaml", "create") 98 Expect(b).Should(BeTrue()) 99 } 100 }) 101 It(" configure pg cluster version", func() { 102 clusterVersion := "kubectl get ClusterVersion | grep postgresql-14.7.2-latest | awk '{print $1}'" 103 if checkResourceExists(clusterVersion) { 104 log.Println("postgresql-14.7.2-latest clusterVersion already exists") 105 } else { 106 b := e2eutil.OpsYaml(dir+"/testdata/config/postgresql_cv.yaml", "create") 107 Expect(b).Should(BeTrue()) 108 } 109 }) 110 }) 111 } 112 113 func DeleteConfig() { 114 BeforeEach(func() { 115 }) 116 117 AfterEach(func() { 118 }) 119 120 Context("delete e2e test resources", func() { 121 It("Check backup exists ", func() { 122 backupArr := e2eutil.ExecCommandReadline("kubectl get backup | awk '{print $1}'") 123 if len(backupArr) > 0 { 124 deleteResource("kubectl delete backup --all") 125 } 126 }) 127 It("delete secret and backuprepo", func() { 128 deleteResource("kubectl delete secret " + ConfigType + "-credential-for-backuprepo -n kb-system") 129 deleteResource("kubectl delete backuprepo my-repo") 130 }) 131 132 It("delete resources", func() { 133 deleteResource("kubectl delete ComponentResourceConstraint kb-resource-constraint-e2e") 134 deleteResource("kubectl delete ComponentClassDefinition custom-class") 135 }) 136 137 It("delete cv", func() { 138 deleteResource("kubectl delete ClusterVersion postgresql-14.7.2-latest") 139 }) 140 141 It("delete clusters", func() { 142 deleteResource("kubectl delete cluster --all") 143 }) 144 }) 145 } 146 147 func checkResourceExists(command string) bool { 148 if len(e2eutil.ExecCommand(command)) > 0 { 149 return true 150 } 151 return false 152 } 153 154 func deleteResource(cmd string) { 155 deleteCv := e2eutil.ExecuteCommand(cmd) 156 Expect(deleteCv).Should(BeTrue()) 157 }