You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by zh...@apache.org on 2022/07/25 06:07:54 UTC

[apisix-ingress-controller] branch master updated: test: keep namespace when test failed in dev mod (#1158)

This is an automated email from the ASF dual-hosted git repository.

zhangjintao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git


The following commit(s) were added to refs/heads/master by this push:
     new 1765ec9f test: keep namespace when test failed in dev mod (#1158)
1765ec9f is described below

commit 1765ec9ffe683a323fd3a851e0ea069173950481
Author: lsy <70...@users.noreply.github.com>
AuthorDate: Mon Jul 25 14:07:49 2022 +0800

    test: keep namespace when test failed in dev mod (#1158)
    
    Co-authored-by: Jintao Zhang <zh...@gmail.com>
---
 .github/workflows/e2e-test-ci.yml |  1 +
 Makefile                          |  3 ++-
 test/e2e/README.md                |  2 ++
 test/e2e/scaffold/scaffold.go     | 48 ++++++++++++++++++++++-----------------
 4 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/.github/workflows/e2e-test-ci.yml b/.github/workflows/e2e-test-ci.yml
index 5d9d34f1..a09ec7e3 100644
--- a/.github/workflows/e2e-test-ci.yml
+++ b/.github/workflows/e2e-test-ci.yml
@@ -185,5 +185,6 @@ jobs:
           ENABLE_PROXY: "false"
           E2E_SKIP_BUILD: "1"
           E2E_FLAKE_ATTEMPTS: "2"
+          E2E_ENV: "ci"
         run: |
           make e2e-test
diff --git a/Makefile b/Makefile
index 7412f1ac..bcd6ecbc 100644
--- a/Makefile
+++ b/Makefile
@@ -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
@@ -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
diff --git a/test/e2e/README.md b/test/e2e/README.md
index c915a617..acc4d949 100644
--- a/test/e2e/README.md
+++ b/test/e2e/README.md
@@ -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
 -------
diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go
index 629f0efa..13c3f342 100644
--- a/test/e2e/scaffold/scaffold.go
+++ b/test/e2e/scaffold/scaffold.go
@@ -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)
 	}