Skip to content

Commit 5f5eb82

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 858b04b commit 5f5eb82

File tree

21 files changed

+142
-56
lines changed

21 files changed

+142
-56
lines changed

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

Lines changed: 0 additions & 3 deletions
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

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,32 @@ 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: setup-test-e2e
73+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
74+
@command -v $(KIND) >/dev/null 2>&1 || { \
75+
echo "Kind is not installed. Please install Kind manually."; \
76+
exit 1; \
77+
}
78+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
79+
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
80+
$(KIND) create cluster --name project-test-e2e --wait 5m; \
81+
}
82+
7283
.PHONY: test-e2e
73-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
85+
go test ./test/e2e/ -v -ginkgo.v
86+
87+
.PHONY: teardown-test-e2e
88+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7489
@command -v $(KIND) >/dev/null 2>&1 || { \
7590
echo "Kind is not installed. Please install Kind manually."; \
7691
exit 1; \
7792
}
78-
@$(KIND) get clusters | grep -q 'kind' || { \
79-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
93+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
94+
echo "Kind cluster project-test-e2e not found."; \
8095
exit 1; \
8196
}
82-
go test ./test/e2e/ -v -ginkgo.v
97+
@$(KIND) delete cluster --name project-test-e2e
8398

8499
.PHONY: lint
85100
lint: golangci-lint ## Run golangci-lint linter

docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := "project-test-e2e"
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}

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

Lines changed: 0 additions & 3 deletions
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

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,32 @@ 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: setup-test-e2e
69+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
70+
@command -v $(KIND) >/dev/null 2>&1 || { \
71+
echo "Kind is not installed. Please install Kind manually."; \
72+
exit 1; \
73+
}
74+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
75+
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
76+
$(KIND) create cluster --name project-test-e2e --wait 5m; \
77+
}
78+
6879
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
81+
go test ./test/e2e/ -v -ginkgo.v
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7085
@command -v $(KIND) >/dev/null 2>&1 || { \
7186
echo "Kind is not installed. Please install Kind manually."; \
7287
exit 1; \
7388
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
89+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
90+
echo "Kind cluster project-test-e2e not found."; \
7691
exit 1; \
7792
}
78-
go test ./test/e2e/ -v -ginkgo.v
93+
@$(KIND) delete cluster --name project-test-e2e
7994

8095
.PHONY: lint
8196
lint: golangci-lint ## Run golangci-lint linter

docs/book/src/getting-started/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := "project-test-e2e"
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}

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

Lines changed: 0 additions & 3 deletions
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

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,32 @@ 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: setup-test-e2e
73+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
74+
@command -v $(KIND) >/dev/null 2>&1 || { \
75+
echo "Kind is not installed. Please install Kind manually."; \
76+
exit 1; \
77+
}
78+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
79+
echo "Kind cluster not running, creating Kind cluster: project-test-e2e"; \
80+
$(KIND) create cluster --name project-test-e2e --wait 5m; \
81+
}
82+
7283
.PHONY: test-e2e
73-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
84+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
85+
go test ./test/e2e/ -v -ginkgo.v
86+
87+
.PHONY: teardown-test-e2e
88+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7489
@command -v $(KIND) >/dev/null 2>&1 || { \
7590
echo "Kind is not installed. Please install Kind manually."; \
7691
exit 1; \
7792
}
78-
@$(KIND) get clusters | grep -q 'kind' || { \
79-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
93+
@$(KIND) get clusters | grep -q 'project-test-e2e' || { \
94+
echo "Kind cluster project-test-e2e not found."; \
8095
exit 1; \
8196
}
82-
go test ./test/e2e/ -v -ginkgo.v
97+
@$(KIND) delete cluster --name project-test-e2e
8398

8499
.PHONY: lint
85100
lint: golangci-lint ## Run golangci-lint linter

docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := "project-test-e2e"
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}

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

Lines changed: 1 addition & 3 deletions
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

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,32 @@ 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: setup-test-e2e
148+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
149+
@command -v $(KIND) >/dev/null 2>&1 || { \
150+
echo "Kind is not installed. Please install Kind manually."; \
151+
exit 1; \
152+
}
153+
@$(KIND) get clusters | grep -q '{{ .ProjectName }}-test-e2e' || { \
154+
echo "Kind cluster not running, creating Kind cluster: {{ .ProjectName }}-test-e2e"; \
155+
$(KIND) create cluster --name {{ .ProjectName }}-test-e2e --wait 5m; \
156+
}
157+
147158
.PHONY: test-e2e
148-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
159+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
160+
go test ./test/e2e/ -v -ginkgo.v
161+
162+
.PHONY: teardown-test-e2e
163+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
149164
@command -v $(KIND) >/dev/null 2>&1 || { \
150165
echo "Kind is not installed. Please install Kind manually."; \
151166
exit 1; \
152167
}
153-
@$(KIND) get clusters | grep -q 'kind' || { \
154-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
168+
@$(KIND) get clusters | grep -q '{{ .ProjectName }}-test-e2e' || { \
169+
echo "Kind cluster {{ .ProjectName }}-test-e2e not found."; \
155170
exit 1; \
156171
}
157-
go test ./test/e2e/ -v -ginkgo.v
172+
@$(KIND) delete cluster --name {{ .ProjectName }}-test-e2e
158173
159174
.PHONY: lint
160175
lint: golangci-lint ## Run golangci-lint linter

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

Lines changed: 2 additions & 1 deletion
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
@@ -194,7 +195,7 @@ func IsCertManagerCRDsInstalled() bool {
194195
195196
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
196197
func LoadImageToKindClusterWithName(name string) error {
197-
cluster := "kind"
198+
cluster := "{{ .ProjectName }}-test-e2e"
198199
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
199200
cluster = v
200201
}

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

Lines changed: 0 additions & 3 deletions
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

testdata/project-v4-multigroup/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,32 @@ 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: setup-test-e2e
69+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
70+
@command -v $(KIND) >/dev/null 2>&1 || { \
71+
echo "Kind is not installed. Please install Kind manually."; \
72+
exit 1; \
73+
}
74+
@$(KIND) get clusters | grep -q 'project-v4-multigroup-test-e2e' || { \
75+
echo "Kind cluster not running, creating Kind cluster: project-v4-multigroup-test-e2e"; \
76+
$(KIND) create cluster --name project-v4-multigroup-test-e2e --wait 5m; \
77+
}
78+
6879
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
81+
go test ./test/e2e/ -v -ginkgo.v
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7085
@command -v $(KIND) >/dev/null 2>&1 || { \
7186
echo "Kind is not installed. Please install Kind manually."; \
7287
exit 1; \
7388
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
89+
@$(KIND) get clusters | grep -q 'project-v4-multigroup-test-e2e' || { \
90+
echo "Kind cluster project-v4-multigroup-test-e2e not found."; \
7691
exit 1; \
7792
}
78-
go test ./test/e2e/ -v -ginkgo.v
93+
@$(KIND) delete cluster --name project-v4-multigroup-test-e2e
7994

8095
.PHONY: lint
8196
lint: golangci-lint ## Run golangci-lint linter

testdata/project-v4-multigroup/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := "project-v4-multigroup-test-e2e"
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}

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

Lines changed: 0 additions & 3 deletions
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

testdata/project-v4-with-plugins/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,32 @@ 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: setup-test-e2e
69+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
70+
@command -v $(KIND) >/dev/null 2>&1 || { \
71+
echo "Kind is not installed. Please install Kind manually."; \
72+
exit 1; \
73+
}
74+
@$(KIND) get clusters | grep -q 'project-v4-with-plugins-test-e2e' || { \
75+
echo "Kind cluster not running, creating Kind cluster: project-v4-with-plugins-test-e2e"; \
76+
$(KIND) create cluster --name project-v4-with-plugins-test-e2e --wait 5m; \
77+
}
78+
6879
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
81+
go test ./test/e2e/ -v -ginkgo.v
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7085
@command -v $(KIND) >/dev/null 2>&1 || { \
7186
echo "Kind is not installed. Please install Kind manually."; \
7287
exit 1; \
7388
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
89+
@$(KIND) get clusters | grep -q 'project-v4-with-plugins-test-e2e' || { \
90+
echo "Kind cluster project-v4-with-plugins-test-e2e not found."; \
7691
exit 1; \
7792
}
78-
go test ./test/e2e/ -v -ginkgo.v
93+
@$(KIND) delete cluster --name project-v4-with-plugins-test-e2e
7994

8095
.PHONY: lint
8196
lint: golangci-lint ## Run golangci-lint linter

testdata/project-v4-with-plugins/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func IsCertManagerCRDsInstalled() bool {
167167

168168
// LoadImageToKindClusterWithName loads a local docker image to the kind cluster
169169
func LoadImageToKindClusterWithName(name string) error {
170-
cluster := "kind"
170+
cluster := "project-v4-with-plugins-test-e2e"
171171
if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
172172
cluster = v
173173
}

testdata/project-v4/.github/workflows/test-e2e.yml

Lines changed: 0 additions & 3 deletions
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

testdata/project-v4/Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,32 @@ 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: setup-test-e2e
69+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
70+
@command -v $(KIND) >/dev/null 2>&1 || { \
71+
echo "Kind is not installed. Please install Kind manually."; \
72+
exit 1; \
73+
}
74+
@$(KIND) get clusters | grep -q 'project-v4-test-e2e' || { \
75+
echo "Kind cluster not running, creating Kind cluster: project-v4-test-e2e"; \
76+
$(KIND) create cluster --name project-v4-test-e2e --wait 5m; \
77+
}
78+
6879
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
80+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
81+
go test ./test/e2e/ -v -ginkgo.v
82+
83+
.PHONY: teardown-test-e2e
84+
teardown-test-e2e: ## Tear down the Kind cluster used for e2e tests
7085
@command -v $(KIND) >/dev/null 2>&1 || { \
7186
echo "Kind is not installed. Please install Kind manually."; \
7287
exit 1; \
7388
}
74-
@$(KIND) get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
89+
@$(KIND) get clusters | grep -q 'project-v4-test-e2e' || { \
90+
echo "Kind cluster project-v4-test-e2e not found."; \
7691
exit 1; \
7792
}
78-
go test ./test/e2e/ -v -ginkgo.v
93+
@$(KIND) delete cluster --name project-v4-test-e2e
7994

8095
.PHONY: lint
8196
lint: golangci-lint ## Run golangci-lint linter

0 commit comments

Comments
 (0)