From 93a0231c112a7fc4b4d2f64f32e552cdc2664113 Mon Sep 17 00:00:00 2001 From: Kersten Burkhardt Date: Thu, 19 Jun 2025 07:33:34 +0200 Subject: [PATCH] feat(makefile): add setup test e2e targets Introduce optional targets to be executed after setting up the Kind cluster and before running e2e tests. This allows for additional customization and setup steps to be included in the e2e test workflow. --- docs/book/src/cronjob-tutorial/testdata/project/Makefile | 5 ++++- docs/book/src/getting-started/testdata/project/Makefile | 5 ++++- .../book/src/multiversion-tutorial/testdata/project/Makefile | 5 ++++- .../golang/v4/scaffolds/internal/templates/makefile.go | 5 ++++- testdata/project-v4-multigroup/Makefile | 5 ++++- testdata/project-v4-multigroup/go.mod | 2 +- testdata/project-v4-with-plugins/Makefile | 5 ++++- testdata/project-v4/Makefile | 5 ++++- testdata/project-v4/go.mod | 2 +- 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index 6ed03834fd8..b4eb76f5fe4 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -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 || { \ @@ -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 diff --git a/docs/book/src/getting-started/testdata/project/Makefile b/docs/book/src/getting-started/testdata/project/Makefile index e4853ada9a2..79ccba8361b 100644 --- a/docs/book/src/getting-started/testdata/project/Makefile +++ b/docs/book/src/getting-started/testdata/project/Makefile @@ -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 || { \ @@ -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 diff --git a/docs/book/src/multiversion-tutorial/testdata/project/Makefile b/docs/book/src/multiversion-tutorial/testdata/project/Makefile index 6ed03834fd8..b4eb76f5fe4 100644 --- a/docs/book/src/multiversion-tutorial/testdata/project/Makefile +++ b/docs/book/src/multiversion-tutorial/testdata/project/Makefile @@ -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 || { \ @@ -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 diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index 6e403cbfeb6..21cd774a72b 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -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 || { \ @@ -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 diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index d60b2d5d402..4598e18b15c 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -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 || { \ @@ -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 diff --git a/testdata/project-v4-multigroup/go.mod b/testdata/project-v4-multigroup/go.mod index cd57ba08186..8ca19c87533 100644 --- a/testdata/project-v4-multigroup/go.mod +++ b/testdata/project-v4-multigroup/go.mod @@ -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 diff --git a/testdata/project-v4-with-plugins/Makefile b/testdata/project-v4-with-plugins/Makefile index 8e316b8a4c4..cbf808fa36a 100644 --- a/testdata/project-v4-with-plugins/Makefile +++ b/testdata/project-v4-with-plugins/Makefile @@ -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 || { \ @@ -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 diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index d8fd3d0f010..e7db02d0a17 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -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 || { \ @@ -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 diff --git a/testdata/project-v4/go.mod b/testdata/project-v4/go.mod index ebfb0b1f412..faa842214b5 100644 --- a/testdata/project-v4/go.mod +++ b/testdata/project-v4/go.mod @@ -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