github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/multicluster/examples/helidon-ns-ops/helidon_example_delete_ns_test.go (about) 1 // Copyright (c) 2021, 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package mcnshelidon 5 6 import ( 7 "fmt" 8 dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump" 9 10 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 11 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics" 12 13 "os" 14 "time" 15 16 "github.com/verrazzano/verrazzano/pkg/k8s/resource" 17 18 . "github.com/onsi/ginkgo/v2" 19 . "github.com/onsi/gomega" 20 "github.com/verrazzano/verrazzano/tests/e2e/multicluster/examples" 21 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 22 ) 23 24 const ( 25 pollingInterval = 5 * time.Second 26 waitTimeout = 5 * time.Minute 27 consistentlyDuration = 1 * time.Minute 28 sourceDir = "hello-helidon-ns" 29 testNamespace = "hello-helidon-ns" 30 testProjectName = "hello-helidon-ns" 31 ) 32 33 var adminKubeconfig = os.Getenv("ADMIN_KUBECONFIG") 34 var managedKubeconfig = os.Getenv("MANAGED_KUBECONFIG") 35 36 // failed indicates whether any of the tests has failed 37 var failed = false 38 var beforeSuitePassed = false 39 40 var t = framework.NewTestFramework("mcnshelidon") 41 42 var _ = t.AfterEach(func() { 43 // set failed to true if any of the tests has failed 44 failed = failed || CurrentSpecReport().Failed() 45 }) 46 47 // set the kubeconfig to use the admin cluster kubeconfig and deploy the example resources 48 var beforeSuite = t.BeforeSuiteFunc(func() { 49 // deploy the VerrazzanoProject 50 start := time.Now() 51 Eventually(func() error { 52 return examples.DeployHelloHelidonProject(adminKubeconfig, sourceDir) 53 }, waitTimeout, pollingInterval).ShouldNot(HaveOccurred()) 54 55 // wait for the namespace to be created on the cluster before deploying app 56 Eventually(func() bool { 57 return examples.HelidonNamespaceExists(adminKubeconfig, sourceDir) 58 }, waitTimeout, pollingInterval).Should(BeTrue()) 59 60 Eventually(func() error { 61 return examples.DeployHelloHelidonApp(adminKubeconfig, sourceDir) 62 }, waitTimeout, pollingInterval).ShouldNot(HaveOccurred()) 63 beforeSuitePassed = true 64 metrics.Emit(t.Metrics.With("deployment_elapsed_time", time.Since(start).Milliseconds())) 65 }) 66 67 var _ = BeforeSuite(beforeSuite) 68 69 var _ = t.Describe("In Multi-cluster, verify delete ns of hello-helidon-ns", Label("f:multicluster.mc-app-lcm"), func() { 70 t.Context("Admin Cluster", func() { 71 // GIVEN an admin cluster and at least one managed cluster 72 // WHEN the example application has been deployed to the admin cluster 73 // THEN expect that the multi-cluster resources have been created on the admin cluster 74 t.It("Has multi cluster resources", func() { 75 Eventually(func() bool { 76 return examples.VerifyMCResources(adminKubeconfig, true, false, testNamespace) 77 }, waitTimeout, pollingInterval).Should(BeTrue()) 78 }) 79 // GIVEN an admin cluster 80 // WHEN the multi-cluster example application has been created on admin cluster but not placed there 81 // THEN expect that the app is not deployed to the admin cluster consistently for some length of time 82 t.It("Does not have application placed", func() { 83 Consistently(func() bool { 84 result, err := examples.VerifyHelloHelidonInCluster(adminKubeconfig, true, false, testProjectName, testNamespace) 85 if err != nil { 86 AbortSuite(fmt.Sprintf("One or more pods are not running in the namespace: %v, error: %v", testNamespace, err)) 87 } 88 return result 89 }, consistentlyDuration, pollingInterval).Should(BeTrue()) 90 }) 91 }) 92 93 t.Context("Managed Cluster", func() { 94 // GIVEN an admin cluster and at least one managed cluster 95 // WHEN the example application has been deployed to the admin cluster 96 // THEN expect that the multi-cluster resources have been created on the managed cluster 97 t.It("Has multi cluster resources", func() { 98 Eventually(func() bool { 99 return examples.VerifyMCResources(managedKubeconfig, false, true, testNamespace) 100 }, waitTimeout, pollingInterval).Should(BeTrue()) 101 }) 102 // GIVEN an admin cluster and at least one managed cluster 103 // WHEN the multi-cluster example application has been created on admin cluster and placed in managed cluster 104 // THEN expect that the app is deployed to the managed cluster 105 t.It("Has application placed", func() { 106 Eventually(func() bool { 107 result, err := examples.VerifyHelloHelidonInCluster(managedKubeconfig, false, true, testProjectName, testNamespace) 108 if err != nil { 109 AbortSuite(fmt.Sprintf("One or more pods are not running in the namespace: %v, error: %v", testNamespace, err)) 110 } 111 return result 112 }, waitTimeout, pollingInterval).Should(BeTrue()) 113 }) 114 }) 115 116 t.Context("Delete resources", func() { 117 t.It("Delete project on admin cluster", func() { 118 Eventually(func() error { 119 return deleteProject(adminKubeconfig) 120 }, waitTimeout, pollingInterval).ShouldNot(HaveOccurred()) 121 }) 122 123 t.It("Delete test namespace on managed cluster", func() { 124 Eventually(func() error { 125 return pkg.DeleteNamespaceInCluster(testNamespace, managedKubeconfig) 126 }, waitTimeout, pollingInterval).ShouldNot(HaveOccurred()) 127 }) 128 129 t.It("Verify deletion on managed cluster", func() { 130 Eventually(func() bool { 131 return examples.VerifyHelloHelidonDeletedInManagedCluster(managedKubeconfig, testNamespace, testProjectName) 132 }, waitTimeout, pollingInterval).Should(BeTrue()) 133 }) 134 135 t.It("Delete test namespace on admin cluster", func() { 136 Eventually(func() error { 137 return pkg.DeleteNamespaceInCluster(testNamespace, adminKubeconfig) 138 }, waitTimeout, pollingInterval).ShouldNot(HaveOccurred()) 139 }) 140 141 t.It("Verify deletion on admin cluster", func() { 142 Eventually(func() bool { 143 return examples.VerifyHelloHelidonDeletedAdminCluster(adminKubeconfig, false, testNamespace, testProjectName) 144 }, waitTimeout, pollingInterval).Should(BeTrue()) 145 }) 146 147 }) 148 }) 149 150 var afterSuite = t.AfterSuiteFunc(func() { 151 if failed || !beforeSuitePassed { 152 dump.ExecuteBugReport(testNamespace) 153 } 154 }) 155 156 var _ = AfterSuite(afterSuite) 157 158 func deleteProject(kubeconfigPath string) error { 159 start := time.Now() 160 file, err := pkg.FindTestDataFile("examples/multicluster/hello-helidon-ns/verrazzano-project.yaml") 161 if err != nil { 162 return err 163 } 164 if err := resource.DeleteResourceFromFileInCluster(file, kubeconfigPath); err != nil { 165 return fmt.Errorf("failed to delete hello-helidon project resource: %v", err) 166 } 167 metrics.Emit(t.Metrics.With("undeployment_elapsed_time", time.Since(start).Milliseconds())) 168 return nil 169 }