Merge pull request #33981 from freehan/e2e-deletens-on-failure

Automatic merge from submit-queue

add delete-namespace-on-failure flag

I have been doing this for a while. 

Setting `--delete-namespace=false --clean-start=true` only works if you have only one e2e test running in a loop. 

This PR lets someone to set `delete-namespace-on-failure=false` and run multiple tests in parallel and preserve the crime scene. It makes it easier to reproduce failures. 

Let me know if this is worth it or there are some other tricks I am not aware.
This commit is contained in:
Kubernetes Submit Queue
2016-10-07 04:34:27 -07:00
committed by GitHub
4 changed files with 16 additions and 2 deletions

View File

@@ -315,7 +315,10 @@ func (f *Framework) AfterEach() {
// expectation failures preventing deleting the namespace.
defer func() {
nsDeletionErrors := map[string]error{}
if TestContext.DeleteNamespace {
// Whether to delete namespace is determined by 3 factors: delete-namespace flag, delete-namespace-on-failure flag and the test result
// if delete-namespace set to false, namespace will always be preserved.
// if delete-namespace is true and delete-namespace-on-failure is false, namespace will be preserved if test failed.
if TestContext.DeleteNamespace && (TestContext.DeleteNamespaceOnFailure || !CurrentGinkgoTestDescription().Failed) {
for _, ns := range f.namespacesToDelete {
By(fmt.Sprintf("Destroying namespace %q for this suite.", ns.Name))
timeout := 5 * time.Minute
@@ -333,7 +336,12 @@ func (f *Framework) AfterEach() {
// Delete the federation namespace.
f.deleteFederationNs()
} else {
Logf("Found DeleteNamespace=false, skipping namespace deletion!")
if TestContext.DeleteNamespace {
Logf("Found DeleteNamespace=false, skipping namespace deletion!")
} else if TestContext.DeleteNamespaceOnFailure {
Logf("Found DeleteNamespaceOnFailure=false, skipping namespace deletion!")
}
}
// Paranoia-- prevent reuse!