From 87e8877065399f2792288abf611fae2e1089b228 Mon Sep 17 00:00:00 2001 From: Congrool Date: Wed, 16 Nov 2022 10:13:51 +0800 Subject: [PATCH] retry deleting ns after reconnect cloud node Signed-off-by: Congrool --- test/e2e/autonomy/autonomy_test.go | 13 +++++++------ test/e2e/common/ns/ns.go | 5 ++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/e2e/autonomy/autonomy_test.go b/test/e2e/autonomy/autonomy_test.go index 32e45e1c6cf..d663f394ddc 100644 --- a/test/e2e/autonomy/autonomy_test.go +++ b/test/e2e/autonomy/autonomy_test.go @@ -210,10 +210,10 @@ var _ = ginkgo.BeforeSuite(func() { gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to get client set") err = ns.DeleteNameSpace(c, YurtE2ENamespaceName) - util.ExpectNoError(err) + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "failed to delete namespace") ginkgo.By("create e2e-test namespace") _, err = ns.CreateNameSpace(c, YurtE2ENamespaceName) - gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to create namespaces") + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to create namespace") // get nginx podIP on edge node worker2 cs := c @@ -251,13 +251,14 @@ var _ = ginkgo.BeforeSuite(func() { var _ = ginkgo.AfterSuite(func() { // reconnect cloud node to docker network cmd := exec.Command("/bin/bash", "-c", "docker network connect kind "+YurtCloudNodeName) - error := cmd.Run() - gomega.Expect(error).NotTo(gomega.HaveOccurred(), "fail to reconnect cloud node to kind bridge") + err := cmd.Run() + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to reconnect cloud node to kind bridge") klog.Infof("successfully reconnected cloud node") ginkgo.By("delete namespace:" + YurtE2ENamespaceName) - err = ns.DeleteNameSpace(c, YurtE2ENamespaceName) - gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to delete created namespaces") + gomega.Eventually(func() error { + return ns.DeleteNameSpace(c, YurtE2ENamespaceName) + }).WithTimeout(10 * time.Second).WithPolling(1 * time.Second).Should(gomega.Succeed()) }) func TestEdgeAutonomy(t *testing.T) { diff --git a/test/e2e/common/ns/ns.go b/test/e2e/common/ns/ns.go index 467d397129b..d89d67c4938 100644 --- a/test/e2e/common/ns/ns.go +++ b/test/e2e/common/ns/ns.go @@ -19,7 +19,6 @@ package ns import ( "context" - "github.com/onsi/gomega" apiv1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,8 +32,8 @@ func DeleteNameSpace(c clientset.Interface, ns string) (err error) { err = c.CoreV1().Namespaces().Delete(context.Background(), ns, metav1.DeleteOptions{ PropagationPolicy: &deletePolicy, }) - if !apierrs.IsNotFound(err) { - gomega.Expect(err).NotTo(gomega.HaveOccurred(), "fail to delete created namespaces:"+ns) + if err != nil && !apierrs.IsNotFound(err) { + return } err = util.WaitForNamespacesDeleted(c, []string{ns}, util.DefaultNamespaceDeletionTimeout) return