Skip to content

Commit

Permalink
test: keep namespace when test failed in dev mod (#1158)
Browse files Browse the repository at this point in the history
Co-authored-by: Jintao Zhang <zhangjintao9020@gmail.com>
  • Loading branch information
stillfox-lee and tao12345666333 committed Jul 25, 2022
1 parent b1add53 commit 1765ec9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,6 @@ jobs:
ENABLE_PROXY: "false"
E2E_SKIP_BUILD: "1"
E2E_FLAKE_ATTEMPTS: "2"
E2E_ENV: "ci"
run: |
make e2e-test
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GO_LDFLAGS ?= "-X=$(VERSYM)=$(VERSION) -X=$(GITSHASYM)=$(GITSHA) -X=$(BUILDOSSYM
E2E_NODES ?= 4
E2E_FLAKE_ATTEMPTS ?= 0
E2E_SKIP_BUILD ?= 0
E2E_ENV ?= "dev"

### build: Build apisix-ingress-controller
.PHONY: build
Expand Down Expand Up @@ -129,7 +130,7 @@ e2e-test: ginkgo-check pack-images e2e-wolf-rbac
cd test/e2e \
&& go mod download \
&& export REGISTRY=$(REGISTRY) \
&& ACK_GINKGO_RC=true ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --nodes=$(E2E_NODES) --focus=$(E2E_FOCUS) --flake-attempts=$(E2E_FLAKE_ATTEMPTS)
&& E2E_ENV=$(E2E_ENV) ACK_GINKGO_RC=true ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --nodes=$(E2E_NODES) --focus=$(E2E_FOCUS) --flake-attempts=$(E2E_FLAKE_ATTEMPTS)

### e2e-test-local: Run e2e test cases (kind is required)
.PHONY: e2e-test-local
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ a e2e test scaffold is prepared to run test cases easily. The source codes are i
* Create a http server with [kennethreitz/httpbin](https://hub.docker.com/r/kennethreitz/httpbin/) as the upstream.

The above mentioned steps are run before each case starts and all resources will be destroyed after the case finishes.
Sepecially, if test case failed and e2e-test run in dev mode, the related resources will not be destroyed. This fearure is useful for debugging.
Also, you can disable this feature by unset `E2E_ENV=dev`.

Plugins
-------
Expand Down
48 changes: 27 additions & 21 deletions test/e2e/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,30 +427,36 @@ func (s *Scaffold) afterEach() {
defer ginkgo.GinkgoRecover()

if ginkgo.CurrentSpecReport().Failed() {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, "Dumping namespace contents")
output, _ := k8s.RunKubectlAndGetOutputE(ginkgo.GinkgoT(), s.kubectlOptions, "get", "deploy,sts,svc,pods")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
output, _ = k8s.RunKubectlAndGetOutputE(ginkgo.GinkgoT(), s.kubectlOptions, "describe", "pods")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
// Get the logs of apisix
output = s.GetDeploymentLogs("apisix-deployment-e2e-test")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
// Get the logs of ingress
output = s.GetDeploymentLogs("ingress-apisix-controller-deployment-e2e-test")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
if os.Getenv("E2E_ENV") != "dev" {
// dump and delete related resource
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, "Dumping namespace contents")
output, _ := k8s.RunKubectlAndGetOutputE(ginkgo.GinkgoT(), s.kubectlOptions, "get", "deploy,sts,svc,pods")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
output, _ = k8s.RunKubectlAndGetOutputE(ginkgo.GinkgoT(), s.kubectlOptions, "describe", "pods")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
// Get the logs of apisix
output = s.GetDeploymentLogs("apisix-deployment-e2e-test")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
// Get the logs of ingress
output = s.GetDeploymentLogs("ingress-apisix-controller-deployment-e2e-test")
if output != "" {
_, _ = fmt.Fprintln(ginkgo.GinkgoWriter, output)
}
err := k8s.DeleteNamespaceE(s.t, s.kubectlOptions, s.namespace)
assert.Nilf(ginkgo.GinkgoT(), err, "deleting namespace %s", s.namespace)
}
} else {
// if the test case is successful, just delete namespace
err := k8s.DeleteNamespaceE(s.t, s.kubectlOptions, s.namespace)
assert.Nilf(ginkgo.GinkgoT(), err, "deleting namespace %s", s.namespace)
}

err := k8s.DeleteNamespaceE(s.t, s.kubectlOptions, s.namespace)
assert.Nilf(ginkgo.GinkgoT(), err, "deleting namespace %s", s.namespace)

for _, f := range s.finializers {
runWithRecover(f)
}
Expand Down

0 comments on commit 1765ec9

Please sign in to comment.