Skip to content

✨ feat(makefile): add setup test e2e targets #4876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/book/src/cronjob-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=
Copy link
Member

@camilamacedo86 camilamacedo86 Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution 🥇

But let's check the motivation:

By introducing the SETUP_TEST_E2E_TARGETS variable, users gain the flexibility to define and run one or more prerequisite targets prior to cluster setup and test execution. This change:

Do we have any prerequisites in the default scaffold?

Currently, the test-e2e target in the Kubebuilder Makefile template hardcodes a single workflow: setup the Kind cluster and immediately run the end-to-end tests. This prevents projects from injecting any preparatory steps - such as installing CRDs, operators, or other third-party dependencies - before executing the actual tests.

The key question here is: Do we need to support this in the default scaffold?

I would argue no. This kind of setup is only necessary in customised use cases. If someone chooses to modify the default scaffold to accommodate these advanced workflows, they can and should customise the Makefile accordingly as well.

In other words, we shouldn’t change the default scaffold to support edge-case scenarios that are irrelevant to the standard use case. Doing so introduces unnecessary complexity and maintenance burden, with features that don’t offer value to the common path.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/hold for we discuss the need and motivations ^


.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -80,7 +83,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
5 changes: 4 additions & 1 deletion docs/book/src/getting-started/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -76,7 +79,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -80,7 +83,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= {{ .ProjectName }}-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -155,7 +158,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
5 changes: 4 additions & 1 deletion testdata/project-v4-multigroup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-v4-multigroup-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -76,7 +79,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v4-multigroup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup
go 1.24.0

require (
github.com/cert-manager/cert-manager v1.18.0
github.com/cert-manager/cert-manager v1.18.1
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.1
k8s.io/api v0.33.0
Expand Down
5 changes: 4 additions & 1 deletion testdata/project-v4-with-plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-v4-with-plugins-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -76,7 +79,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
5 changes: 4 additions & 1 deletion testdata/project-v4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ test: manifests generate fmt vet setup-envtest ## Run tests.
# - CERT_MANAGER_INSTALL_SKIP=true
KIND_CLUSTER ?= project-v4-test-e2e

# Optional targets to run after setting up Kind cluster and before running e2e tests
SETUP_TEST_E2E_TARGETS ?=

.PHONY: setup-test-e2e
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
@command -v $(KIND) >/dev/null 2>&1 || { \
Expand All @@ -76,7 +79,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
$(KIND) create cluster --name $(KIND_CLUSTER)

.PHONY: test-e2e
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: $(SETUP_TEST_E2E_TARGETS) setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v4/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v4
go 1.24.0

require (
github.com/cert-manager/cert-manager v1.18.0
github.com/cert-manager/cert-manager v1.18.1
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.1
k8s.io/api v0.33.0
Expand Down