From cfc54d216d543907f2ad036c60a059ccfac9a55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Luk=C5=A1a?= Date: Thu, 10 Oct 2024 16:42:46 +0200 Subject: [PATCH] Faster cleanup in dualstack_test.go (#404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marko Lukša --- tests/e2e/dualstack/dualstack_test.go | 6 ++---- tests/e2e/util/kubectl/kubectl.go | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/e2e/dualstack/dualstack_test.go b/tests/e2e/dualstack/dualstack_test.go index b4108509b..e213c3d5e 100644 --- a/tests/e2e/dualstack/dualstack_test.go +++ b/tests/e2e/dualstack/dualstack_test.go @@ -244,10 +244,8 @@ spec: AfterAll(func(ctx SpecContext) { By("Deleting the pods") - Expect(k.DeleteNamespace(DualStackNamespace)).To(Succeed(), fmt.Sprintf("Failed to delete the %q namespace", DualStackNamespace)) - Expect(k.DeleteNamespace(IPv4Namespace)).To(Succeed(), fmt.Sprintf("Failed to delete the %q namespace", IPv4Namespace)) - Expect(k.DeleteNamespace(IPv6Namespace)).To(Succeed(), fmt.Sprintf("Failed to delete the %q namespace", IPv6Namespace)) - Expect(k.DeleteNamespace(SleepNamespace)).To(Succeed(), fmt.Sprintf("Failed to delete the %q namespace", SleepNamespace)) + Expect(k.DeleteNamespace(DualStackNamespace, IPv4Namespace, IPv6Namespace, SleepNamespace)). + To(Succeed(), "Failed to delete namespaces") Success("DualStack validation pods deleted") }) }) diff --git a/tests/e2e/util/kubectl/kubectl.go b/tests/e2e/util/kubectl/kubectl.go index 28e5b0adf..5c92fbee0 100644 --- a/tests/e2e/util/kubectl/kubectl.go +++ b/tests/e2e/util/kubectl/kubectl.go @@ -124,17 +124,17 @@ func (k Kubectl) DeleteCRDs(crds []string) error { } // DeleteNamespaceNoWait deletes a namespace and returns immediately (without waiting for the namespace to be removed). -func (k Kubectl) DeleteNamespaceNoWait(ns string) error { - return k.deleteNamespace(ns, false) +func (k Kubectl) DeleteNamespaceNoWait(namespaces ...string) error { + return k.deleteNamespace(namespaces, false) } // DeleteNamespace deletes a namespace and waits for it to be removed completely. -func (k Kubectl) DeleteNamespace(ns string) error { - return k.deleteNamespace(ns, true) +func (k Kubectl) DeleteNamespace(namespaces ...string) error { + return k.deleteNamespace(namespaces, true) } -func (k Kubectl) deleteNamespace(ns string, wait bool) error { - cmd := k.build(" delete namespace " + ns + " --wait=" + strconv.FormatBool(wait)) +func (k Kubectl) deleteNamespace(namespaces []string, wait bool) error { + cmd := k.build(" delete namespace " + strings.Join(namespaces, " ") + " --wait=" + strconv.FormatBool(wait)) _, err := k.executeCommand(cmd) if err != nil { return fmt.Errorf("error deleting namespace: %w", err)