From febaefce4d404601c2fc2d7bd68b109af8b96200 Mon Sep 17 00:00:00 2001 From: Zhiwei Yin Date: Tue, 21 Jan 2025 16:20:24 +0800 Subject: [PATCH] fix integration test random failure Signed-off-by: Zhiwei Yin --- .../operator/clustermanager_aws_test.go | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/test/integration/operator/clustermanager_aws_test.go b/test/integration/operator/clustermanager_aws_test.go index 1388d55f0..65c1222f9 100644 --- a/test/integration/operator/clustermanager_aws_test.go +++ b/test/integration/operator/clustermanager_aws_test.go @@ -30,24 +30,38 @@ var _ = ginkgo.Describe("ClusterManager Default Mode with aws registration", fun }) ginkgo.Context("Deploy hub with aws auth", func() { - - ginkgo.It("should have IAM role annotation when initialized with awsirsa", func() { - - clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - - if clusterManager.Spec.RegistrationConfiguration == nil { - clusterManager.Spec.RegistrationConfiguration = &operatorapiv1.RegistrationHubConfiguration{} - clusterManager.Spec.RegistrationConfiguration.RegistrationDrivers = []operatorapiv1.RegistrationDriverHub{ - { - AuthType: "awsirsa", - HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster", - }, + ginkgo.BeforeEach(func() { + gomega.Eventually(func() error { + clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{}) + if err != nil { + return err } - } - _, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + if clusterManager.Spec.RegistrationConfiguration == nil { + clusterManager.Spec.RegistrationConfiguration = &operatorapiv1.RegistrationHubConfiguration{} + clusterManager.Spec.RegistrationConfiguration.RegistrationDrivers = []operatorapiv1.RegistrationDriverHub{ + { + AuthType: "awsirsa", + HubClusterArn: "arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster", + }, + } + } + _, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{}) + return err + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) + }) + ginkgo.AfterEach(func() { + gomega.Eventually(func() error { + clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{}) + if err != nil { + return err + } + clusterManager.Spec.RegistrationConfiguration = nil + _, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{}) + return err + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) + }) + ginkgo.It("should have IAM role annotation when initialized with awsirsa", func() { gomega.Eventually(func() bool { registrationControllerSA, err := kubeClient.CoreV1().ServiceAccounts(hubNamespace).Get( context.Background(), hubRegistrationSA, metav1.GetOptions{}) @@ -56,18 +70,8 @@ var _ = ginkgo.Describe("ClusterManager Default Mode with aws registration", fun } annotation := registrationControllerSA.Annotations["eks.amazonaws.com/role-arn"] - // The same cluster-manager CR is used for other tests. - // Hence updating it here, so that annotation is removed for other test testing with csr or empty registration - clusterManager, err := operatorClient.OperatorV1().ClusterManagers().Get(context.Background(), clusterManagerName, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - clusterManager.Spec.RegistrationConfiguration = nil - _, err = operatorClient.OperatorV1().ClusterManagers().Update(context.Background(), clusterManager, metav1.UpdateOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) - return annotation == "arn:aws:iam::123456789012:role/hub-cluster_managed-cluster-identity-creator" }, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue()) - }) }) - })