From 565f97bf68e794cd4b0a86399294bf2682383d8d Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Sun, 15 Apr 2018 20:15:01 -0400 Subject: [PATCH] Allow a test suite reusing framework to register namespaces to delete If the suite bypasses CreateNamespace (because it wants to create more specialized namespaces) it has no way to register deletes. --- test/e2e/framework/framework.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index c81442154f3..4aca7e1d541 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -399,10 +399,7 @@ func (f *Framework) CreateNamespace(baseName string, labels map[string]string) ( ns, err := createTestingNS(baseName, f.ClientSet, labels) // check ns instead of err to see if it's nil as we may // fail to create serviceAccount in it. - // In this case, we should not forget to delete the namespace. - if ns != nil { - f.namespacesToDelete = append(f.namespacesToDelete, ns) - } + f.AddNamespacesToDelete(ns) if err == nil && !f.SkipPrivilegedPSPBinding { CreatePrivilegedPSPBinding(f, ns.Name) @@ -411,6 +408,18 @@ func (f *Framework) CreateNamespace(baseName string, labels map[string]string) ( return ns, err } +// AddNamespacesToDelete adds one or more namespaces to be deleted when the test +// completes. +func (f *Framework) AddNamespacesToDelete(namespaces ...*v1.Namespace) { + for _, ns := range namespaces { + if ns == nil { + continue + } + f.namespacesToDelete = append(f.namespacesToDelete, ns) + + } +} + // WaitForPodTerminated waits for the pod to be terminated with the given reason. func (f *Framework) WaitForPodTerminated(podName, reason string) error { return waitForPodTerminatedInNamespace(f.ClientSet, podName, reason, f.Namespace.Name)