github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/jaeger-operator/jaeger_operator_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 jaegeroperator 5 6 import ( 7 "fmt" 8 "strings" 9 "time" 10 11 . "github.com/onsi/ginkgo/v2" 12 . "github.com/onsi/gomega" 13 "github.com/verrazzano/verrazzano/pkg/k8sutil" 14 "github.com/verrazzano/verrazzano/platform-operator/constants" 15 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 16 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 17 ) 18 19 const ( 20 waitTimeout = 3 * time.Minute 21 pollingInterval = 10 * time.Second 22 jaegerOperatorName = "jaeger-operator" 23 minVZVersion = "1.3.0" 24 jaegerESIndexCleanerJob = "jaeger-operator-jaeger-es-index-cleaner" 25 ) 26 27 var ( 28 jaegerOperatorCrds = []string{ 29 "jaegers.jaegertracing.io", 30 } 31 imagePrefix = pkg.GetImagePrefix() 32 operatorImage = imagePrefix + "/verrazzano/" + jaegerOperatorName 33 expectedJaegerImages = map[string]string{ 34 "JAEGER-AGENT-IMAGE": imagePrefix + "/verrazzano/jaeger-agent", 35 "JAEGER-COLLECTOR-IMAGE": imagePrefix + "/verrazzano/jaeger-collector", 36 "JAEGER-QUERY-IMAGE": imagePrefix + "/verrazzano/jaeger-query", 37 "JAEGER-INGESTER-IMAGE": imagePrefix + "/verrazzano/jaeger-ingester", 38 "JAEGER-ES-INDEX-CLEANER-IMAGE": imagePrefix + "/verrazzano/jaeger-es-index-cleaner", 39 "JAEGER-ES-ROLLOVER-IMAGE": imagePrefix + "/verrazzano/jaeger-es-rollover", 40 "JAEGER-ALL-IN-ONE-IMAGE": imagePrefix + "/verrazzano/jaeger-all-in-one", 41 } 42 ) 43 44 var t = framework.NewTestFramework("jaegeroperator") 45 46 func WhenJaegerOperatorEnabledIt(text string, args ...interface{}) { 47 kubeconfig, err := k8sutil.GetKubeConfigLocation() 48 if err != nil { 49 t.It(text, func() { 50 Fail(err.Error()) 51 }) 52 } 53 if pkg.IsJaegerOperatorEnabled(kubeconfig) { 54 t.ItMinimumVersion(text, minVZVersion, kubeconfig, args...) 55 } 56 t.Logs.Infof("Skipping spec, Jaeger Operator is disabled") 57 } 58 59 var _ = t.Describe("Jaeger Operator", Label("f:platform-lcm.install"), func() { 60 t.Context("after successful installation", func() { 61 // GIVEN the Jaeger Operator is installed 62 // WHEN we check to make sure the namespace exists 63 // THEN we successfully find the namespace 64 WhenJaegerOperatorEnabledIt("should have a verrazzano-monitoring namespace", func() { 65 Eventually(func() (bool, error) { 66 return pkg.DoesNamespaceExist(constants.VerrazzanoMonitoringNamespace) 67 }).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue()) 68 }) 69 70 // GIVEN the Jaeger Operator is installed 71 // WHEN we check to make sure the Jaeger pods are running 72 // THEN we successfully find the running pods 73 // For 1.3.0, only the jaeger-operator pod gets created and its status is validated 74 // For 1.4.0 and later, jaeger-operator, jaeger-operator-jaeger-query, jaeger-operator-jaeger-collector 75 // pods gets created and their status is validated. 76 WhenJaegerOperatorEnabledIt("should have running pods", func() { 77 jaegerOperatorPodsRunning := func() bool { 78 result, err := pkg.PodsRunning(constants.VerrazzanoMonitoringNamespace, []string{jaegerOperatorName}) 79 if err != nil { 80 AbortSuite(fmt.Sprintf("Pod %v is not running in the namespace: %v, error: %v", jaegerOperatorName, constants.VerrazzanoMonitoringNamespace, err)) 81 } 82 return result 83 } 84 Eventually(jaegerOperatorPodsRunning).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue()) 85 }) 86 87 // GIVEN the Jaeger Operator is installed 88 // WHEN we check to make sure the default Jaeger images are from Verrazzano 89 // THEN we see that the env is correctly populated 90 WhenJaegerOperatorEnabledIt("should have the correct default Jaeger images", func() { 91 verifyImages := func() bool { 92 // Check if Jaeger operator is running with the expected Verrazzano Jaeger Operator image 93 image, err := pkg.GetContainerImage(constants.VerrazzanoMonitoringNamespace, jaegerOperatorName, jaegerOperatorName) 94 if err != nil { 95 pkg.Log(pkg.Error, fmt.Sprintf("Container %s is not running in the namespace: %s, error: %v", jaegerOperatorName, constants.VerrazzanoMonitoringNamespace, err)) 96 return false 97 } 98 if !strings.HasPrefix(image, operatorImage) { 99 pkg.Log(pkg.Error, fmt.Sprintf("Container %s image %s is not running with the expected image %s in the namespace: %s", jaegerOperatorName, image, operatorImage, constants.VerrazzanoMonitoringNamespace)) 100 return false 101 } 102 // Check if Jaeger operator env has been set to use Verrazzano Jaeger images 103 containerEnv, err := pkg.GetContainerEnv(constants.VerrazzanoMonitoringNamespace, jaegerOperatorName, jaegerOperatorName) 104 if err != nil { 105 pkg.Log(pkg.Error, fmt.Sprintf("Not able to get the environment variables in the container %s, error: %v", jaegerOperatorName, err)) 106 return false 107 } 108 for name, val := range expectedJaegerImages { 109 found := false 110 for _, actualEnv := range containerEnv { 111 if actualEnv.Name == name { 112 if !strings.HasPrefix(actualEnv.Value, val) { 113 pkg.Log(pkg.Error, fmt.Sprintf("The value %s of the env %s for the container %s does not have the image %s as expected", 114 actualEnv.Value, actualEnv.Name, jaegerOperatorName, val)) 115 return false 116 } 117 found = true 118 } 119 } 120 if !found { 121 pkg.Log(pkg.Error, fmt.Sprintf("The env %s not set for the container %s", name, jaegerOperatorName)) 122 return false 123 } 124 } 125 return true 126 } 127 Eventually(verifyImages).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue()) 128 }) 129 130 // GIVEN the Jaeger Operator is installed 131 // WHEN we check the CRDs created by Jaeger Operator 132 // THEN we successfully find the Jaeger CRDs 133 WhenJaegerOperatorEnabledIt("should have the correct Jaeger Operator CRDs", func() { 134 verifyCRDList := func() (bool, error) { 135 for _, crd := range jaegerOperatorCrds { 136 exists, err := pkg.DoesCRDExist(crd) 137 if err != nil || !exists { 138 return exists, err 139 } 140 } 141 return true, nil 142 } 143 Eventually(verifyCRDList).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue()) 144 }) 145 146 // GIVEN the Jaeger Operator is installed 147 // WHEN we check to make sure the Jaeger OpenSearch Index Cleaner cron job exists 148 // THEN we successfully find the expected cron job 149 WhenJaegerOperatorEnabledIt("should have a Jaeger OpenSearch Index Cleaner cron job", func() { 150 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 151 if err != nil { 152 Fail(err.Error()) 153 } 154 create, err := pkg.IsJaegerInstanceCreated(kubeconfigPath) 155 if err != nil { 156 Fail(err.Error()) 157 } 158 if !create { 159 Skip("Default Jaeger instance is not created in this cluster") 160 } 161 Eventually(func() (bool, error) { 162 pkg.Log(pkg.Info, fmt.Sprintf("Default Jaeger instance exists, checking if %s cron job exists", jaegerESIndexCleanerJob)) 163 return pkg.DoesCronJobExist(kubeconfigPath, constants.VerrazzanoMonitoringNamespace, jaegerESIndexCleanerJob) 164 }).WithPolling(pollingInterval).WithTimeout(waitTimeout).Should(BeTrue()) 165 }) 166 }) 167 })