github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/multicluster/verify-jaeger/helidon/jaeger_helidon_mc_test.go (about) 1 // Copyright (c) 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 helidon 5 6 import ( 7 "fmt" 8 dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump" 9 "os" 10 "time" 11 12 "github.com/verrazzano/verrazzano/pkg/k8s/resource" 13 14 . "github.com/onsi/ginkgo/v2" 15 . "github.com/onsi/gomega" 16 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 17 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 18 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework/metrics" 19 ) 20 21 const ( 22 shortPollingInterval = 10 * time.Second 23 shortWaitTimeout = 5 * time.Minute 24 projectName = "hello-helidon-jaeger" 25 ) 26 27 const ( 28 testAppComponentFilePath = "testdata/jaeger/helidon/multicluster/mc-helidon-tracing-comp.yaml" 29 testAppConfigurationFilePath = "testdata/jaeger/helidon/multicluster/mc-helidon-tracing-app.yaml" 30 verrazzanoProjectFilePath = "testdata/jaeger/helidon/multicluster/helidon-verrazzano-project.yaml" 31 ) 32 33 var ( 34 t = framework.NewTestFramework("jaeger-mc-helidon") 35 expectedPodsHelloHelidon = []string{"hello-helidon-deployment"} 36 beforeSuitePassed = false 37 failed = false 38 start = time.Now() 39 helloHelidonServiceName = "hello-helidon-jaeger-mc" 40 ) 41 42 var adminKubeconfig = os.Getenv("ADMIN_KUBECONFIG") 43 var managedKubeconfig = os.Getenv("MANAGED_KUBECONFIG") 44 var managedClusterName = os.Getenv("MANAGED_CLUSTER_NAME") 45 46 var beforeSuite = t.BeforeSuiteFunc(func() { 47 start = time.Now() 48 // set the kubeconfig to use the admin cluster kubeconfig and deploy the example resources 49 50 if adminKubeconfig == "" || managedKubeconfig == "" || managedClusterName == "" { 51 AbortSuite("One or more required env variables (ADMIN_KUBECONFIG, MANAGED_KUBECONFIG, MANAGED_CLUSTER_NAME) for the test suite are not set.") 52 } 53 // deploy the VerrazzanoProject 54 start := time.Now() 55 Eventually(func() error { 56 file, err := pkg.FindTestDataFile(verrazzanoProjectFilePath) 57 if err != nil { 58 return err 59 } 60 if err := resource.CreateOrUpdateResourceFromFileInCluster(file, adminKubeconfig); err != nil { 61 return fmt.Errorf("failed to create %s project resource: %v", projectName, err) 62 } 63 return nil 64 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 65 66 // wait for the namespace to be created on the cluster before deploying app 67 Eventually(func() bool { 68 _, err := pkg.GetNamespaceInCluster(projectName, adminKubeconfig) 69 return err == nil 70 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue()) 71 72 Eventually(func() error { 73 file, err := pkg.FindTestDataFile(testAppComponentFilePath) 74 if err != nil { 75 return err 76 } 77 if err := resource.CreateOrUpdateResourceFromFileInCluster(file, adminKubeconfig); err != nil { 78 return fmt.Errorf("failed to create multi-cluster %s component resources: %v", projectName, err) 79 } 80 file, err = pkg.FindTestDataFile(testAppConfigurationFilePath) 81 if err != nil { 82 return err 83 } 84 if err := resource.CreateOrUpdateResourceFromFileInCluster(file, adminKubeconfig); err != nil { 85 return fmt.Errorf("failed to create multi-cluster %s application resource: %v", projectName, err) 86 } 87 return nil 88 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 89 Eventually(func() bool { 90 result, err := pkg.PodsRunningInCluster(projectName, expectedPodsHelloHelidon, managedKubeconfig) 91 if err != nil { 92 return false 93 } 94 return result 95 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue()) 96 metrics.Emit(t.Metrics.With("deployment_elapsed_time", time.Since(start).Milliseconds())) 97 err := pkg.GenerateTrafficForTraces(projectName, "", "greet", managedKubeconfig) 98 if err != nil { 99 pkg.Log(pkg.Error, "Unable to send traffic requests to generate traces") 100 } 101 beforeSuitePassed = true 102 }) 103 104 var _ = BeforeSuite(beforeSuite) 105 106 var _ = t.AfterEach(func() { 107 failed = failed || CurrentSpecReport().Failed() 108 }) 109 110 var afterSuite = t.AfterSuiteFunc(func() { 111 if failed || !beforeSuitePassed { 112 err := dump.ExecuteBugReport(projectName) 113 if err != nil { 114 pkg.Log(pkg.Error, err.Error()) 115 } 116 } 117 // undeploy the application here 118 start := time.Now() 119 Eventually(func() error { 120 file, err := pkg.FindTestDataFile(testAppConfigurationFilePath) 121 if err != nil { 122 return err 123 } 124 if err := resource.DeleteResourceFromFileInCluster(file, adminKubeconfig); err != nil { 125 return fmt.Errorf("failed to delete multi-cluster hello-helidon application resource: %v", err) 126 } 127 return nil 128 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 129 Eventually(func() error { 130 file, err := pkg.FindTestDataFile(testAppComponentFilePath) 131 if err != nil { 132 return err 133 } 134 if err := resource.DeleteResourceFromFileInCluster(file, adminKubeconfig); err != nil { 135 return fmt.Errorf("failed to delete multi-cluster hello-helidon component resources: %v", err) 136 } 137 return nil 138 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 139 140 Eventually(func() error { 141 file, err := pkg.FindTestDataFile(verrazzanoProjectFilePath) 142 if err != nil { 143 return err 144 } 145 if err := resource.DeleteResourceFromFileInCluster(file, adminKubeconfig); err != nil { 146 return fmt.Errorf("failed to delete hello-helidon project resource: %v", err) 147 } 148 return nil 149 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 150 151 Eventually(func() error { 152 return pkg.DeleteNamespaceInCluster(projectName, managedKubeconfig) 153 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 154 Eventually(func() error { 155 return pkg.DeleteNamespaceInCluster(projectName, adminKubeconfig) 156 }).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).ShouldNot(HaveOccurred()) 157 158 metrics.Emit(t.Metrics.With("undeployment_elapsed_time", time.Since(start).Milliseconds())) 159 }) 160 161 var _ = AfterSuite(afterSuite) 162 163 var _ = t.Describe("Helidon App with Jaeger Traces", Label("f:jaeger.helidon-workload"), func() { 164 t.Context("after successful installation", func() { 165 // GIVEN the Jaeger Operator is enabled and a sample application is installed, 166 // WHEN we check for traces for that service, 167 // THEN we are able to get the traces 168 t.It("traces for the helidon app should be available when queried from Jaeger", func() { 169 validatorFn := pkg.ValidateApplicationTracesInCluster(adminKubeconfig, start, helloHelidonServiceName, managedClusterName) 170 Eventually(validatorFn).WithPolling(shortPollingInterval).WithTimeout(shortWaitTimeout).Should(BeTrue()) 171 }) 172 173 }) 174 })