github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/clusteragent/cluster_agent_test.go (about) 1 // Copyright (c) 2023, 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 clusteragent 5 6 import ( 7 "fmt" 8 "time" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 "github.com/verrazzano/verrazzano/pkg/k8sutil" 13 "github.com/verrazzano/verrazzano/platform-operator/constants" 14 "github.com/verrazzano/verrazzano/tests/e2e/pkg" 15 "github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework" 16 ) 17 18 const ( 19 waitTimeout = 3 * time.Minute 20 pollingInterval = 10 * time.Second 21 clusterAgentPodPrefix = "verrazzano-cluster-agent" 22 ) 23 24 var t = framework.NewTestFramework("clusteragent") 25 26 func getKubeConfigOrAbort() string { 27 kubeconfigPath, err := k8sutil.GetKubeConfigLocation() 28 if err != nil { 29 AbortSuite(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error())) 30 } 31 return kubeconfigPath 32 } 33 34 func clusterAgentInstalled() bool { 35 kubeconfigPath := getKubeConfigOrAbort() 36 isMinVersion160, err := pkg.IsVerrazzanoMinVersion("1.6.0", kubeconfigPath) 37 if err != nil { 38 Fail(err.Error()) 39 } 40 clusterAgentEnabled := pkg.IsClusterAgentEnabled(kubeconfigPath) 41 return isMinVersion160 && clusterAgentEnabled 42 } 43 44 // 'It' Wrapper to only run spec if the Cluster Agent is supported on the current Verrazzano version 45 func WhenClusterAgentInstalledIt(description string, f func()) { 46 if clusterAgentInstalled() { 47 t.It(description, f) 48 } else { 49 t.Logs.Infof("Skipping check '%v', the Cluster Agent is not supported", description) 50 } 51 } 52 53 // 'DescribeTable' Wrapper to only run spec if the Cluster Agent is supported on the current Verrazzano version 54 func WhenClusterAgentInstalledDescribetable(description string, args ...interface{}) { 55 if clusterAgentInstalled() { 56 t.DescribeTable(description, args...) 57 } else { 58 t.Logs.Infof("Skipping check '%v', the Cluster Agent is not supported", description) 59 } 60 } 61 62 var _ = t.Describe("Cluster Agent", Label("f:platform-lcm.install"), func() { 63 t.Context("after successful installation", func() { 64 65 // GIVEN the Cluster Agent is installed 66 // WHEN we check to make sure the pods are running 67 // THEN we successfully find the running pods 68 WhenClusterAgentInstalledIt("should have running pods", func() { 69 podsRunning := func() (bool, error) { 70 result, err := pkg.PodsRunning(constants.VerrazzanoSystemNamespace, []string{clusterAgentPodPrefix}) 71 if err != nil { 72 t.Logs.Errorf("Pod %v is not running in the namespace: %v, error: %v", clusterAgentPodPrefix, constants.VerrazzanoSystemNamespace, err) 73 } 74 return result, err 75 } 76 Eventually(podsRunning, waitTimeout, pollingInterval).Should(BeTrue()) 77 }) 78 79 // GIVEN the Cluster Agent is installed 80 // WHEN the installation is successful 81 // THEN we find the expected CRDs 82 WhenClusterAgentInstalledDescribetable("CRD for", 83 func(name string) { 84 Eventually(func() (bool, error) { 85 return pkg.DoesCRDExist(name) 86 }, waitTimeout, pollingInterval).Should(BeTrue()) 87 }, 88 t.Entry("multiclusterapplicationconfigurations should exist in cluster", "multiclusterapplicationconfigurations.clusters.verrazzano.io"), 89 t.Entry("multiclustercomponents should exist in cluster", "multiclustercomponents.clusters.verrazzano.io"), 90 t.Entry("multiclusterconfigmaps should exist in cluster", "multiclusterconfigmaps.clusters.verrazzano.io"), 91 t.Entry("multiclustersecrets should exist in cluster", "multiclustersecrets.clusters.verrazzano.io"), 92 t.Entry("verrazzanoprojects should exist in cluster", "verrazzanoprojects.clusters.verrazzano.io"), 93 ) 94 }) 95 })