github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/test/e2e/installation/installcheck.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package installation 18 19 import ( 20 "context" 21 "log" 22 23 . "github.com/onsi/ginkgo/v2" 24 . "github.com/onsi/gomega" 25 "helm.sh/helm/v3/pkg/action" 26 "helm.sh/helm/v3/pkg/cli/values" 27 "helm.sh/helm/v3/pkg/repo" 28 corev1 "k8s.io/api/core/v1" 29 "sigs.k8s.io/controller-runtime/pkg/client" 30 31 . "github.com/1aal/kubeblocks/test/e2e" 32 "github.com/1aal/kubeblocks/test/testutils" 33 ) 34 35 const releaseName = "kubeblocks" 36 const releaseNS = "kubeblocks-e2e-test" 37 38 var chart = testutils.InstallOpts{ 39 Name: releaseName, 40 Chart: "kubeblocks/kubeblocks", 41 Wait: true, 42 Namespace: releaseNS, 43 ValueOpts: &values.Options{ 44 Values: []string{ 45 "image.pullPolicy=Always", 46 "wesql.enabled=false", 47 }, 48 }, 49 TryTimes: 2, 50 CreateNamespace: true, 51 } 52 53 func InstallationTest() { 54 55 BeforeEach(func() { 56 57 }) 58 59 AfterEach(func() { 60 }) 61 62 Context("KubeBlocks installation", func() { 63 AfterEach(func() { 64 }) 65 66 It("add repo", func() { 67 err := testutils.AddRepo(&repo.Entry{Name: testutils.KubeBlocksRepoName, URL: testutils.GetHelmChartRepoURL()}) 68 Expect(err).NotTo(HaveOccurred()) 69 }) 70 71 It("Install KubeBlocks via Helm", func() { 72 cfg := getHelmConfig() 73 log.Println("Version: " + Version) 74 chart.Version = Version 75 _, err := chart.Install(cfg) 76 Expect(err).NotTo(HaveOccurred()) 77 // Expect(notes).NotTo(BeEmpty()) 78 }) 79 }) 80 } 81 82 func UninstallationTest() { 83 84 BeforeEach(func() { 85 }) 86 87 AfterEach(func() { 88 }) 89 90 Context("KubeBlocks uninstallation", func() { 91 AfterEach(func() { 92 }) 93 94 It("Uninstall KubeBlocks via Helm", func() { 95 uninstallHelmRelease() 96 }) 97 }) 98 } 99 100 func CheckedUninstallHelmRelease() { 101 cfg := getHelmConfig() 102 actionCfg := getHelmActionCfg(cfg) 103 res, err := chart.GetInstalled(actionCfg) 104 if res == nil { 105 return 106 } 107 Expect(err).NotTo(HaveOccurred()) 108 109 Expect(chart.Uninstall(cfg)).NotTo(HaveOccurred()) 110 uninstallHelmRelease() 111 } 112 113 func getHelmConfig() *testutils.Config { 114 return testutils.NewConfig(releaseNS, "", "", false) 115 } 116 117 func getHelmActionCfg(cfg *testutils.Config) *action.Configuration { 118 actionCfg, err := testutils.NewActionConfig(cfg) 119 Expect(err).NotTo(HaveOccurred()) 120 Expect(actionCfg).NotTo(BeNil()) 121 return actionCfg 122 } 123 124 func uninstallHelmRelease() { 125 ctx := context.Background() 126 ns := &corev1.Namespace{} 127 Expect(K8sClient.Get(ctx, client.ObjectKey{ 128 Name: releaseNS, 129 }, ns)).NotTo(HaveOccurred()) 130 Expect(K8sClient.Delete(ctx, ns)).NotTo(HaveOccurred()) 131 }