Skip to content

Commit

Permalink
e2e framework: add -skip-cleanup flag to allow skipping any clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
SataQiu committed Feb 9, 2020
1 parent ea11971 commit 82d08c1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
31 changes: 31 additions & 0 deletions test/framework/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package framework

import (
"flag"
)

var (
// SkipCleanup indicates whether the cleanup after the test is skipped.
// Default: false
SkipCleanup bool
)

func init() {
flag.BoolVar(&SkipCleanup, "skip-cleanup", SkipCleanup, "if true, the cleanup after the test will be skipped")
}
2 changes: 1 addition & 1 deletion test/infrastructure/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PULL_POLICY ?= Always
all: test manager clusterctl

help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[0-9A-Za-z_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

## --------------------------------------
## Testing
Expand Down
12 changes: 9 additions & 3 deletions test/infrastructure/docker/e2e/docker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ var _ = BeforeSuite(func() {
Expect(err).ShouldNot(HaveOccurred())
Expect(config).ShouldNot(BeNil())

if framework.SkipCleanup {
By("skip-cleanup flag is specified, the cleanup after the test will be skipped")
}

By("creating the logs directory")
artifactPath := os.Getenv("ARTIFACTS")
logPath = path.Join(artifactPath, "logs")
Expand Down Expand Up @@ -112,9 +116,11 @@ var _ = AfterSuite(func() {
Expect(writeLogs(mgmt, "capi-kubeadm-bootstrap-system", "capi-kubeadm-bootstrap-controller-manager", logPath)).To(Succeed())
Expect(writeLogs(mgmt, "capi-kubeadm-control-plane-system", "capi-kubeadm-control-plane-controller-manager", logPath)).To(Succeed())
Expect(writeLogs(mgmt, "capd-system", "capd-controller-manager", logPath)).To(Succeed())
By("Deleting the management cluster")
// If any part of teardown fails it will print what must be manually cleaned up
mgmt.Teardown(ctx)
if !framework.SkipCleanup {
By("Deleting the management cluster")
// If any part of teardown fails it will print what must be manually cleaned up
mgmt.Teardown(ctx)
}
})

func ensureDockerArtifactsDeleted(input *framework.ControlplaneClusterInput) {
Expand Down
4 changes: 3 additions & 1 deletion test/infrastructure/docker/e2e/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ var _ = Describe("Docker", func() {
})

AfterEach(func() {
ensureDockerArtifactsDeleted(input)
if !framework.SkipCleanup {
ensureDockerArtifactsDeleted(input)
}
})

Context("Multi-node controlplane cluster", func() {
Expand Down

0 comments on commit 82d08c1

Please sign in to comment.