Skip to content

Commit

Permalink
Faster cleanup in dualstack_test.go (#404)
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Lukša <[email protected]>
  • Loading branch information
luksa authored Oct 10, 2024
1 parent b263e62 commit cfc54d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions tests/e2e/dualstack/dualstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/util/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cfc54d2

Please sign in to comment.