Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster cleanup in dualstack_test.go #404

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Comment on lines +247 to +248
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this still delete each namespace sequentially by calling DeleteNamespace? Don't you need DeleteNamespaceNoWait(...) and then Wait("delete", "namespace") x 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this immediately marks all specified namespace for deletion and then waits for all of them to disappear. We don't need DeleteNamespaceNoWait() here, as the only reason to use NoWait + Wait is when you're deleting namespaces in multiple clusters.

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