github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/pre-upgrade/metricsbinding/metrics_binding_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 metricsbinding 5 6 import ( 7 "fmt" 8 dump "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/clusterdump" 9 10 . "github.com/onsi/ginkgo/v2" 11 "github.com/verrazzano/verrazzano/pkg/k8sutil" 12 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 13 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 14 ) 15 16 const ( 17 // Define the test namespaces 18 deploymentNamespace = "hello-helidon-deployment" 19 podNamespace = "hello-helidon-pod" 20 replicasetNamespace = "hello-helidon-replicaset" 21 statefulsetNamespace = "hello-helidon-statefulset" 22 23 // Define the test deployment name prefix 24 namePrefix = "hello-helidon-" 25 26 // Define the test yaml file locations 27 deploymentYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-deployment.yaml" 28 podYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-pod.yaml" 29 replicasetYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-replicaset.yaml" 30 statefulsetYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-statefulset.yaml" 31 32 // Define the custom templates 33 legacyVMITemplate = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/legacy-vmi-metrics-template.yaml" 34 externalPromTemplate = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/external-prometheus-metrics-template.yaml" 35 36 // Define the simulated external Prometheus ConfigMap 37 configMapYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/external-prometheus-config.yaml" 38 ) 39 40 var ( 41 t = framework.NewTestFramework("deploymentworkload") 42 clusterDump = dump.NewClusterDumpWrapper(t, deploymentNamespace, podNamespace, replicasetNamespace, statefulsetNamespace) 43 ) 44 45 var _ = clusterDump.AfterEach(func() {}) // Dump cluster if spec fails 46 47 // 'It' Wrapper to only run spec if the Metrics Binding will be created 48 func WhenMetricsBindingInstalledIt(description string, f func()) { 49 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 50 if err != nil { 51 t.It(description, func() { 52 Fail(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error())) 53 }) 54 } 55 vz14OrLater, err := pkg.IsVerrazzanoMinVersion("1.4.0", kubeconfigPath) 56 if err != nil { 57 t.It(description, func() { 58 Fail(fmt.Sprintf("Failed to check Verrazzano version less than 1.4.0: %s", err.Error())) 59 }) 60 } 61 below14 := !vz14OrLater 62 above12, err := pkg.IsVerrazzanoMinVersion("1.2.0", kubeconfigPath) 63 if err != nil { 64 t.It(description, func() { 65 Fail(fmt.Sprintf("Failed to check Verrazzano version at or above 1.2.0: %s", err.Error())) 66 }) 67 } 68 if below14 && above12 { 69 t.It(description, f) 70 } else { 71 t.Logs.Infof("Skipping check '%v', the Metrics Binding is not supported", description) 72 } 73 } 74 75 var _ = t.Describe("Verify", Label("f:app-lcm.poko"), func() { 76 // GIVEN the Verrazzano version 77 // WHEN the sample applications are deployed 78 // THEN no errors should occur 79 t.Context("Deploy and verify the test applications", Label("f:observability.monitoring.prom"), FlakeAttempts(5), func() { 80 WhenMetricsBindingInstalledIt("Apply the Deployment and external Prometheus Metrics Template", func() { 81 createNamespace(deploymentNamespace, "enabled", *t) 82 deployConfigMap(deploymentNamespace, configMapYaml, *t) 83 deployTemplate(deploymentNamespace, externalPromTemplate, *t) 84 deployApplication(deploymentNamespace, deploymentYaml, namePrefix, *t) 85 }) 86 WhenMetricsBindingInstalledIt("Apply the Pod and legacy VMI Metrics Template", func() { 87 createNamespace(podNamespace, "disabled", *t) 88 deployTemplate(podNamespace, legacyVMITemplate, *t) 89 deployApplication(podNamespace, podYaml, namePrefix, *t) 90 }) 91 WhenMetricsBindingInstalledIt("Apply the ReplicaSet", func() { 92 createNamespace(replicasetNamespace, "enabled", *t) 93 deployApplication(replicasetNamespace, replicasetYaml, namePrefix, *t) 94 }) 95 WhenMetricsBindingInstalledIt("Apply the StatefulSet", func() { 96 createNamespace(statefulsetNamespace, "disabled", *t) 97 deployApplication(statefulsetNamespace, statefulsetYaml, namePrefix, *t) 98 }) 99 }) 100 })