diff --git a/cmd/uptest/main.go b/cmd/uptest/main.go index d31da67..076fd6c 100644 --- a/cmd/uptest/main.go +++ b/cmd/uptest/main.go @@ -54,8 +54,9 @@ var ( defaultConditions = e2e.Flag("default-conditions", "Comma separated list of default conditions to wait for a successful test.\n"+ "Conditions could be overridden per resource using \"uptest.upbound.io/conditions\" annotation.").Default("Ready").String() - skipDelete = e2e.Flag("skip-delete", "Skip the delete step of the test.").Default("false").Bool() - testDir = e2e.Flag("test-directory", "Directory where kuttl test case will be generated and executed.").Envar("UPTEST_TEST_DIR").Default(filepath.Join(os.TempDir(), "uptest-e2e")).String() + skipDelete = e2e.Flag("skip-delete", "Skip the delete step of the test.").Default("false").Bool() + testDir = e2e.Flag("test-directory", "Directory where kuttl test case will be generated and executed.").Envar("UPTEST_TEST_DIR").Default(filepath.Join(os.TempDir(), "uptest-e2e")).String() + onlyCleanUptestResources = e2e.Flag("only-clean-uptest-resources", "While deletion step, only clean resources that were created by uptest").Default("false").Bool() ) var ( @@ -115,14 +116,15 @@ func e2eTests() { } } o := &config.AutomatedTest{ - ManifestPaths: examplePaths, - DataSourcePath: *dataSourcePath, - SetupScriptPath: setupPath, - TeardownScriptPath: teardownPath, - DefaultConditions: strings.Split(*defaultConditions, ","), - DefaultTimeout: *defaultTimeout, - Directory: *testDir, - SkipDelete: *skipDelete, + ManifestPaths: examplePaths, + DataSourcePath: *dataSourcePath, + SetupScriptPath: setupPath, + TeardownScriptPath: teardownPath, + DefaultConditions: strings.Split(*defaultConditions, ","), + DefaultTimeout: *defaultTimeout, + Directory: *testDir, + SkipDelete: *skipDelete, + OnlyCleanUptestResources: *onlyCleanUptestResources, } kingpin.FatalIfError(internal.RunTest(o), "cannot run e2e tests successfully") diff --git a/internal/config/config.go b/internal/config/config.go index 77101b2..5a2bc7e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,6 +58,8 @@ type AutomatedTest struct { DefaultConditions []string SkipDelete bool + + OnlyCleanUptestResources bool } // Manifest represents a resource loaded from an example resource manifest file. @@ -72,6 +74,8 @@ type TestCase struct { Timeout int SetupScriptPath string TeardownScriptPath string + + OnlyCleanUptestResources bool } // Resource represents a Kubernetes object to be tested and asserted diff --git a/internal/templates/03-assert.yaml.tmpl b/internal/templates/03-assert.yaml.tmpl index 97849fe..f3b9315 100644 --- a/internal/templates/03-assert.yaml.tmpl +++ b/internal/templates/03-assert.yaml.tmpl @@ -15,7 +15,9 @@ commands: - command: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=delete --timeout 10s {{- end }} {{- end }} +{{- if not .TestCase.OnlyCleanUptestResources }} - command: ${KUBECTL} wait managed --all --for=delete --timeout 10s +{{- end }} {{- if .TestCase.TeardownScriptPath }} - command: {{ .TestCase.TeardownScriptPath }} {{- end }} diff --git a/internal/tester.go b/internal/tester.go index b8e5c9a..a946007 100644 --- a/internal/tester.go +++ b/internal/tester.go @@ -63,9 +63,10 @@ func (t *tester) executeTests() error { func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { //nolint:gocyclo // TODO: can we break this? tc := &config.TestCase{ - Timeout: t.options.DefaultTimeout, - SetupScriptPath: t.options.SetupScriptPath, - TeardownScriptPath: t.options.TeardownScriptPath, + Timeout: t.options.DefaultTimeout, + SetupScriptPath: t.options.SetupScriptPath, + TeardownScriptPath: t.options.TeardownScriptPath, + OnlyCleanUptestResources: t.options.OnlyCleanUptestResources, } examples := make([]config.Resource, 0, len(t.manifests))