github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/upgrade/post-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 yaml file locations
    24  	deploymentYaml  = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-deployment.yaml"
    25  	podYaml         = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-pod.yaml"
    26  	replicasetYaml  = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-replicaset.yaml"
    27  	statefulsetYaml = "tests/e2e/upgrade/pre-upgrade/metricsbinding/testdata/hello-helidon-statefulset.yaml"
    28  )
    29  
    30  var (
    31  	t           = framework.NewTestFramework("deploymentworkload")
    32  	clusterDump = dump.NewClusterDumpWrapper(t, deploymentNamespace, podNamespace, replicasetNamespace, statefulsetNamespace)
    33  )
    34  
    35  var beforeSuite = clusterDump.BeforeSuiteFunc(func() {}) // Needed to initialize cluster dump flags
    36  var _ = clusterDump.AfterEach(func() {})                 // Dump cluster if spec fails
    37  var afterSuite = clusterDump.AfterSuiteFunc(func() {
    38  	undeployApplication(deploymentNamespace, deploymentYaml, *t)
    39  	undeployApplication(podNamespace, podYaml, *t)
    40  	undeployApplication(replicasetNamespace, replicasetYaml, *t)
    41  	undeployApplication(statefulsetNamespace, statefulsetYaml, *t)
    42  })
    43  
    44  var _ = BeforeSuite(beforeSuite)
    45  var _ = AfterSuite(afterSuite)
    46  
    47  // 'It' Wrapper to only run spec if the Metrics Binding verification is supported
    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  	supported, 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  	if supported {
    62  		t.It(description, f)
    63  	} else {
    64  		t.Logs.Infof("Skipping check '%v', the Metrics Binding is not supported", description)
    65  	}
    66  }
    67  
    68  var _ = t.Describe("Verify", Label("f:app-lcm.poko"), func() {
    69  	// GIVEN the Verrazzano version
    70  	// WHEN the Metrics Binding utilities are updated
    71  	// THEN the Metrics Bindings should be deleted for default template and binding
    72  	t.Context("Verify Metrics Bindings are deleted", Label("f:observability.monitoring.prom"), FlakeAttempts(5), func() {
    73  		WhenMetricsBindingInstalledIt("Verify no Metrics Bindings exist in the ReplicaSet namespace", func() {
    74  			verifyMetricsBindingsDeleted(replicasetNamespace, *t)
    75  		})
    76  		WhenMetricsBindingInstalledIt("Verify no Metrics Bindings exist in the StatefulSet namespace", func() {
    77  			verifyMetricsBindingsDeleted(statefulsetNamespace, *t)
    78  		})
    79  	})
    80  })