Skip to content

Commit 1db61f0

Browse files
committed
refactor(e2e-setup): update Kind cluster naming for e2e tests
change default Kind cluster names to be project-specific for e2e tests Previously, the default Kind cluster name was "kind", which could lead to conflicts when running multiple e2e tests concurrently across different projects. This change updates the Kind cluster name to be project-specific, reducing potential conflicts and improving the isolation of e2e test environments.
1 parent 3f3be65 commit 1db61f0

File tree

16 files changed

+103
-73
lines changed

16 files changed

+103
-73
lines changed

Diff for: docs/book/src/cronjob-tutorial/testdata/project/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: docs/book/src/cronjob-tutorial/testdata/project/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6969
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
7070
# CertManager is installed by default; skip with:
7171
# - CERT_MANAGER_INSTALL_SKIP=true
72-
.PHONY: test-e2e
73-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
72+
KIND_CLUSTER ?= project-test-e2e
73+
74+
.PHONY: setup-test-e2e
75+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7476
@command -v $(KIND) >/dev/null 2>&1 || { \
7577
echo "Kind is not installed. Please install Kind manually."; \
7678
exit 1; \
7779
}
78-
@$(KIND) get clusters | grep -q 'kind' || { \
79-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
80-
exit 1; \
81-
}
82-
go test ./test/e2e/ -v -ginkgo.v
80+
$(KIND) create cluster --name $(KIND_CLUSTER)
81+
82+
.PHONY: test-e2e
83+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
85+
$(MAKE) teardown-test-e2e
86+
87+
.PHONY: teardown-test-e2e
88+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
89+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
8390

8491
.PHONY: lint
8592
lint: golangci-lint ## Run golangci-lint linter

Diff for: docs/book/src/getting-started/testdata/project/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: docs/book/src/getting-started/testdata/project/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6565
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6666
# CertManager is installed by default; skip with:
6767
# - CERT_MANAGER_INSTALL_SKIP=true
68-
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
68+
KIND_CLUSTER ?= project-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7072
@command -v $(KIND) >/dev/null 2>&1 || { \
7173
echo "Kind is not installed. Please install Kind manually."; \
7274
exit 1; \
7375
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76-
exit 1; \
77-
}
78-
go test ./test/e2e/ -v -ginkgo.v
76+
$(KIND) create cluster --name $(KIND_CLUSTER)
77+
78+
.PHONY: test-e2e
79+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
81+
$(MAKE) teardown-test-e2e
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
85+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
7986

8087
.PHONY: lint
8188
lint: golangci-lint ## Run golangci-lint linter

Diff for: docs/book/src/multiversion-tutorial/testdata/project/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: docs/book/src/multiversion-tutorial/testdata/project/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6969
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
7070
# CertManager is installed by default; skip with:
7171
# - CERT_MANAGER_INSTALL_SKIP=true
72-
.PHONY: test-e2e
73-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
72+
KIND_CLUSTER ?= project-test-e2e
73+
74+
.PHONY: setup-test-e2e
75+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7476
@command -v $(KIND) >/dev/null 2>&1 || { \
7577
echo "Kind is not installed. Please install Kind manually."; \
7678
exit 1; \
7779
}
78-
@$(KIND) get clusters | grep -q 'kind' || { \
79-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
80-
exit 1; \
81-
}
82-
go test ./test/e2e/ -v -ginkgo.v
80+
$(KIND) create cluster --name $(KIND_CLUSTER)
81+
82+
.PHONY: test-e2e
83+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
85+
$(MAKE) teardown-test-e2e
86+
87+
.PHONY: teardown-test-e2e
88+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
89+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
8390

8491
.PHONY: lint
8592
lint: golangci-lint ## Run golangci-lint linter

Diff for: docs/book/src/reference/envtest.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ func InstallCertManager() error {
315315
316316
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
317317
func LoadImageToKindClusterWithName(name string) error {
318-
cluster := "kind"
319-
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
320-
cluster = v
318+
cluster, ok := os.LookupEnv("KIND_CLUSTER")
319+
if !ok {
320+
return fmt.Errorf("KIND_CLUSTER is not set")
321321
}
322322
323323
kindOptions := []string{"load", "docker-image", name, "--name", cluster}

Diff for: pkg/plugins/golang/v4/scaffolds/internal/templates/github/test-e2e.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var _ machinery.Template = &E2eTestCi{}
2828
type E2eTestCi struct {
2929
machinery.TemplateMixin
3030
machinery.BoilerplateMixin
31+
machinery.ProjectNameMixin
3132
}
3233

3334
// SetTemplateDefaults implements machinery.Template
@@ -71,9 +72,6 @@ jobs:
7172
- name: Verify kind installation
7273
run: kind version
7374
74-
- name: Create kind cluster
75-
run: kind create cluster
76-
7775
- name: Running Test e2e
7876
run: |
7977
go mod tidy

Diff for: pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
144144
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
145145
# CertManager is installed by default; skip with:
146146
# - CERT_MANAGER_INSTALL_SKIP=true
147-
.PHONY: test-e2e
148-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
147+
KIND_CLUSTER ?= {{ .ProjectName }}-test-e2e
148+
149+
.PHONY: setup-test-e2e
150+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
149151
@command -v $(KIND) >/dev/null 2>&1 || { \
150152
echo "Kind is not installed. Please install Kind manually."; \
151153
exit 1; \
152154
}
153-
@$(KIND) get clusters | grep -q 'kind' || { \
154-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
155-
exit 1; \
156-
}
157-
go test ./test/e2e/ -v -ginkgo.v
155+
$(KIND) create cluster --name $(KIND_CLUSTER)
156+
157+
.PHONY: test-e2e
158+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
159+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
160+
$(MAKE) teardown-test-e2e
161+
162+
.PHONY: teardown-test-e2e
163+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
164+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
158165
159166
.PHONY: lint
160167
lint: golangci-lint ## Run golangci-lint linter

Diff for: pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var _ machinery.Template = &Utils{}
2626
type Utils struct {
2727
machinery.TemplateMixin
2828
machinery.BoilerplateMixin
29+
machinery.ProjectNameMixin
2930
}
3031

3132
// SetTemplateDefaults set the defaults for its template

Diff for: testdata/project-v4-multigroup/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: testdata/project-v4-multigroup/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6565
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6666
# CertManager is installed by default; skip with:
6767
# - CERT_MANAGER_INSTALL_SKIP=true
68-
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
68+
KIND_CLUSTER ?= project-v4-multigroup-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7072
@command -v $(KIND) >/dev/null 2>&1 || { \
7173
echo "Kind is not installed. Please install Kind manually."; \
7274
exit 1; \
7375
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76-
exit 1; \
77-
}
78-
go test ./test/e2e/ -v -ginkgo.v
76+
$(KIND) create cluster --name $(KIND_CLUSTER)
77+
78+
.PHONY: test-e2e
79+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
81+
$(MAKE) teardown-test-e2e
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
85+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
7986

8087
.PHONY: lint
8188
lint: golangci-lint ## Run golangci-lint linter

Diff for: testdata/project-v4-with-plugins/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: testdata/project-v4-with-plugins/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6565
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6666
# CertManager is installed by default; skip with:
6767
# - CERT_MANAGER_INSTALL_SKIP=true
68-
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
68+
KIND_CLUSTER ?= project-v4-with-plugins-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7072
@command -v $(KIND) >/dev/null 2>&1 || { \
7173
echo "Kind is not installed. Please install Kind manually."; \
7274
exit 1; \
7375
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76-
exit 1; \
77-
}
78-
go test ./test/e2e/ -v -ginkgo.v
76+
$(KIND) create cluster --name $(KIND_CLUSTER)
77+
78+
.PHONY: test-e2e
79+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
81+
$(MAKE) teardown-test-e2e
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
85+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
7986

8087
.PHONY: lint
8188
lint: golangci-lint ## Run golangci-lint linter

Diff for: testdata/project-v4/.github/workflows/test-e2e.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

Diff for: testdata/project-v4/Makefile

+14-7
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,24 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
6565
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6666
# CertManager is installed by default; skip with:
6767
# - CERT_MANAGER_INSTALL_SKIP=true
68-
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
68+
KIND_CLUSTER ?= project-v4-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
7072
@command -v $(KIND) >/dev/null 2>&1 || { \
7173
echo "Kind is not installed. Please install Kind manually."; \
7274
exit 1; \
7375
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76-
exit 1; \
77-
}
78-
go test ./test/e2e/ -v -ginkgo.v
76+
$(KIND) create cluster --name $(KIND_CLUSTER)
77+
78+
.PHONY: test-e2e
79+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
81+
$(MAKE) teardown-test-e2e
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
85+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
7986

8087
.PHONY: lint
8188
lint: golangci-lint ## Run golangci-lint linter

0 commit comments

Comments
 (0)