Skip to content
Open
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
23 changes: 23 additions & 0 deletions tests/e2e/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2886,3 +2886,26 @@ func (f *Framework) AssertRuleIsNodeType(ruleName, namespace string) error {
func (f *Framework) AssertRuleIsPlatformType(ruleName, namespace string) error {
return f.assertRuleType(ruleName, namespace, "Platform")
}

// waitForNamespaceDeletion waits until a namespace is fully deleted from the cluster
func (f *Framework) waitForNamespaceDeletion(namespace string, retryInterval, timeout time.Duration) error {
err := wait.Poll(retryInterval, timeout, func() (bool, error) {
_, err := f.KubeClient.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
// Namespace is deleted
return true, nil
}
if err != nil {
log.Printf("Error checking namespace %s deletion status: %v, retrying...", namespace, err)
return false, nil
}
log.Printf("Waiting for namespace %s to be fully deleted...", namespace)
return false, nil
})

if err != nil {
return fmt.Errorf("namespace %s was not deleted within timeout: %w", namespace, err)
}
log.Printf("Namespace %s successfully deleted and cleaned up", namespace)
return nil
}
11 changes: 11 additions & 0 deletions tests/e2e/framework/main_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,16 @@ func (f *Framework) TearDown() error {
if err != nil {
return fmt.Errorf("failed to cleanup namespace %s: %w", f.OperatorNamespace, err)
}

// Verify namespace deletion completes successfully
// This ensures that all resources, including those with finalizers, are properly cleaned up
// and that the operator can be deleted without resources getting stuck in terminating state
log.Printf("Verifying namespace %s deletion \n", f.OperatorNamespace)
err = f.waitForNamespaceDeletion(f.OperatorNamespace, time.Second*5, time.Minute*5)
if err != nil {
return fmt.Errorf("namespace %s deletion did not complete: %w", f.OperatorNamespace, err)
}
log.Printf("Namespace %s successfully deleted\n", f.OperatorNamespace)

return nil
}