diff --git a/test/e2e/addon_lease_test.go b/test/e2e/addon_lease_test.go index 335bcdd5c..b450a173f 100644 --- a/test/e2e/addon_lease_test.go +++ b/test/e2e/addon_lease_test.go @@ -17,26 +17,12 @@ import ( "k8s.io/klog/v2" clusterv1 "open-cluster-management.io/api/cluster/v1" - operatorapiv1 "open-cluster-management.io/api/operator/v1" ) var _ = ginkgo.Describe("Addon Health Check", func() { ginkgo.Context("Checking addon lease on managed cluster to update addon status", func() { - var ( - klusterletName string - addOnName string - ) - + var addOnName string ginkgo.BeforeEach(func() { - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } - // create an addon on created managed cluster addOnName = fmt.Sprintf("addon-%s", rand.String(6)) ginkgo.By(fmt.Sprintf("Creating managed cluster addon %q", addOnName)) @@ -54,11 +40,6 @@ var _ = ginkgo.Describe("Addon Health Check", func() { }) ginkgo.AfterEach(func() { - ginkgo.By(fmt.Sprintf("Cleaning managed cluster %q", clusterName)) - if deployKlusterlet { - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - } ginkgo.By(fmt.Sprintf("Cleaning managed cluster addon installation namespace %q", addOnName)) err := t.SpokeKubeClient.CoreV1().Namespaces().Delete(context.TODO(), addOnName, metav1.DeleteOptions{}) gomega.Expect(err).ToNot(gomega.HaveOccurred()) @@ -255,22 +236,8 @@ var _ = ginkgo.Describe("Addon Health Check", func() { }) ginkgo.Context("Checking managed cluster status to update addon status", func() { - var ( - klusterletName string - addOnName string - ) - + var addOnName string ginkgo.BeforeEach(func() { - // create a managed cluster - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } - // create an addon on created managed cluster addOnName = fmt.Sprintf("addon-%s", rand.String(6)) ginkgo.By(fmt.Sprintf("Creating managed cluster addon %q", addOnName)) diff --git a/test/e2e/addon_test.go b/test/e2e/addon_test.go index d903dbd63..90f3ad3e2 100644 --- a/test/e2e/addon_test.go +++ b/test/e2e/addon_test.go @@ -6,26 +6,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/util/rand" - - operatorapiv1 "open-cluster-management.io/api/operator/v1" ) var _ = Describe("Manage the managed cluster addons", func() { - var klusterletName, clusterName, agentNamespace, addOnName string - + var addOnName string BeforeEach(func() { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace = fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) addOnName = fmt.Sprintf("e2e-addon-%s", rand.String(6)) - - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - Expect(err).ToNot(HaveOccurred()) - }) - AfterEach(func() { - By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil()) }) It("Create one managed cluster addon and make sure it is available", func() { diff --git a/test/e2e/addonmanagement_test.go b/test/e2e/addonmanagement_test.go index d9195741b..46528ff37 100644 --- a/test/e2e/addonmanagement_test.go +++ b/test/e2e/addonmanagement_test.go @@ -46,7 +46,7 @@ var ( var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("addon-manager"), func() { addOnName := "hello-template" - var klusterletName, clusterName, agentNamespace, addonInstallNamespace string + var addonInstallNamespace string s := runtime.NewScheme() _ = scheme.AddToScheme(s) @@ -63,10 +63,6 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("ad } ginkgo.BeforeEach(func() { - surfix := rand.String(6) - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", surfix) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", surfix) - agentNamespace = fmt.Sprintf("open-cluster-management-agent-%s", surfix) addonInstallNamespace = fmt.Sprintf("%s-addon", agentNamespace) ginkgo.By("create addon custom sign secret") @@ -94,10 +90,6 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("ad // the addon manager deployment should be running gomega.Eventually(t.CheckHubReady, t.EventuallyTimeout, t.EventuallyInterval).Should(gomega.Succeed()) - _, err = t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - ginkgo.By(fmt.Sprintf("create addon template resources for cluster %v", clusterName)) err = createResourcesFromYamlFiles(context.Background(), t.HubDynamicClient, t.hubRestMapper, s, defaultAddonTemplateReaderManifestsFunc(manifests.AddonManifestFiles, map[string]interface{}{ @@ -166,9 +158,6 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("ad templateagent.AddonManagerNamespace(), customSignerSecretName, err)) } - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - // disable addon management feature gate gomega.Eventually(func() error { clusterManager, err := t.OperatorClient.OperatorV1().ClusterManagers().Get(context.TODO(), "cluster-manager", metav1.GetOptions{}) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 2628e3729..9e6691429 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -2,11 +2,13 @@ package e2e import ( "flag" + "fmt" "testing" "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/util/rand" operatorapiv1 "open-cluster-management.io/api/operator/v1" ) @@ -15,6 +17,8 @@ var t *Tester var ( clusterName string + klusterletName string + agentNamespace string hubKubeconfig string nilExecutorValidating bool deployKlusterlet bool @@ -69,4 +73,25 @@ var _ = BeforeSuite(func() { }, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed()) } Expect(err).ToNot(HaveOccurred()) + + if deployKlusterlet { + klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) + clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) + agentNamespace = fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) + _, err := t.CreateApprovedKlusterlet( + klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) + Expect(err).ToNot(HaveOccurred()) + + defer func() { + By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) + Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil()) + }() + } +}) + +var _ = AfterSuite(func() { + if deployKlusterlet { + By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) + Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil()) + } }) diff --git a/test/e2e/managedcluster_loopback_test.go b/test/e2e/managedcluster_loopback_test.go index f9924c7f3..141030212 100644 --- a/test/e2e/managedcluster_loopback_test.go +++ b/test/e2e/managedcluster_loopback_test.go @@ -20,7 +20,6 @@ import ( addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1" clusterv1 "open-cluster-management.io/api/cluster/v1" clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1" - operatorapiv1 "open-cluster-management.io/api/operator/v1" "open-cluster-management.io/ocm/pkg/registration/clientcert" "open-cluster-management.io/ocm/pkg/registration/helpers" @@ -61,21 +60,11 @@ var _ = ginkgo.Describe("Loopback registration [development]", func() { ginkgo.It("Should register the hub as a managed cluster", func() { var ( - err error - klusterletName string - suffix = rand.String(6) - nsName = fmt.Sprintf("loopback-spoke-%v", suffix) + err error + suffix = rand.String(6) + nsName = fmt.Sprintf("loopback-spoke-%v", suffix) ) ginkgo.By(fmt.Sprintf("Deploying the agent using suffix=%q ns=%q", suffix, nsName)) - clusterName := fmt.Sprintf("loopback-e2e-%v", suffix) - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } var ( managedCluster *clusterv1.ManagedCluster managedClusters = t.ClusterClient.ClusterV1().ManagedClusters() @@ -352,11 +341,6 @@ var _ = ginkgo.Describe("Loopback registration [development]", func() { return errors.IsNotFound(err) }, 90*time.Second, 1*time.Second).Should(gomega.BeTrue()) - if deployKlusterlet { - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - } - ginkgo.By(fmt.Sprintf("Cleaning managed cluster addon installation namespace %q", addOnName)) err = t.SpokeKubeClient.CoreV1().Namespaces().Delete(context.TODO(), addOnName, metav1.DeleteOptions{}) gomega.Expect(err).ToNot(gomega.HaveOccurred()) diff --git a/test/e2e/manifestworkreplicaset_test.go b/test/e2e/manifestworkreplicaset_test.go index 71d0b47e2..3e46d4bee 100644 --- a/test/e2e/manifestworkreplicaset_test.go +++ b/test/e2e/manifestworkreplicaset_test.go @@ -14,7 +14,6 @@ import ( clusterapiv1 "open-cluster-management.io/api/cluster/v1" clusterv1beta1 "open-cluster-management.io/api/cluster/v1beta1" clusterapiv1beta2 "open-cluster-management.io/api/cluster/v1beta2" - operatorapiv1 "open-cluster-management.io/api/operator/v1" workapiv1 "open-cluster-management.io/api/work/v1" workapiv1alpha1 "open-cluster-management.io/api/work/v1alpha1" @@ -46,27 +45,6 @@ var _ = ginkgo.Describe("Test ManifestWorkReplicaSet", func() { }) ginkgo.Context("Creating a ManifestWorkReplicaSet and check created resources", func() { - var klusterletName, clusterName string - ginkgo.JustBeforeEach(func() { - nameSuffix = rand.String(5) - - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } - }) - - ginkgo.JustAfterEach(func() { - if deployKlusterlet { - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - } - }) - ginkgo.It("Should create ManifestWorkReplicaSet successfullt", func() { ginkgo.By("create manifestworkreplicaset") ns1 := fmt.Sprintf("ns1-%s", nameSuffix) diff --git a/test/e2e/work_webhook_test.go b/test/e2e/work_webhook_test.go index ea75186e3..39a4a4fc7 100644 --- a/test/e2e/work_webhook_test.go +++ b/test/e2e/work_webhook_test.go @@ -14,7 +14,6 @@ import ( "k8s.io/client-go/util/retry" workclientset "open-cluster-management.io/api/client/work/clientset/versioned" - operatorapiv1 "open-cluster-management.io/api/operator/v1" workapiv1 "open-cluster-management.io/api/work/v1" "open-cluster-management.io/ocm/test/integration/util" @@ -24,29 +23,16 @@ import ( // and well configured as sanity check. Resource leftovers should be cleaned up on both hub and managed cluster. var _ = ginkgo.Describe("ManifestWork admission webhook", ginkgo.Label("validating-webhook", "sanity-check"), func() { var nameSuffix string - var workName, klusterletName, clusterName string + var workName string ginkgo.BeforeEach(func() { nameSuffix = rand.String(5) workName = fmt.Sprintf("w1-%s", nameSuffix) - - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } }) ginkgo.AfterEach(func() { ginkgo.By(fmt.Sprintf("delete manifestwork %v/%v", clusterName, workName)) gomega.Expect(t.cleanManifestWorks(clusterName, workName)).To(gomega.BeNil()) - if deployKlusterlet { - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - } }) ginkgo.Context("Creating a manifestwork", func() { diff --git a/test/e2e/work_workload_test.go b/test/e2e/work_workload_test.go index 10500c6c8..3ac44093b 100644 --- a/test/e2e/work_workload_test.go +++ b/test/e2e/work_workload_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/util/rand" "k8s.io/utils/pointer" - operatorapiv1 "open-cluster-management.io/api/operator/v1" workapiv1 "open-cluster-management.io/api/work/v1" "open-cluster-management.io/ocm/test/integration/util" @@ -149,31 +148,18 @@ const ( // Test cases with lable "sanity-check" could be ran on an existing enviroment with work agent installed // and well configured as sanity check. Resource leftovers should be cleaned up on both hub and managed cluster. var _ = ginkgo.Describe("Work agent", ginkgo.Label("work-agent", "sanity-check"), func() { - var workName, klusterletName string + var workName string var err error var nameSuffix string ginkgo.BeforeEach(func() { nameSuffix = rand.String(5) workName = fmt.Sprintf("work-%s", nameSuffix) - - if deployKlusterlet { - klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6)) - clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6)) - agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6)) - _, err := t.CreateApprovedKlusterlet( - klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode)) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - } }) ginkgo.AfterEach(func() { ginkgo.By(fmt.Sprintf("delete manifestwork %v/%v", clusterName, workName)) gomega.Expect(t.cleanManifestWorks(clusterName, workName)).To(gomega.BeNil()) - if deployKlusterlet { - ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName)) - gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil()) - } }) ginkgo.Context("Work CRUD", func() {