@@ -43,11 +43,11 @@ help: ## Display this help.
4343
4444.PHONY : manifests
4545manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46- $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
46+ " $( CONTROLLER_GEN) " rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
4747
4848.PHONY : generate
4949generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
50- $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
50+ " $( CONTROLLER_GEN) " object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
5151
5252.PHONY : fmt
5353fmt : # # Run go fmt against code.
@@ -59,35 +59,48 @@ vet: ## Run go vet against code.
5959
6060.PHONY : test
6161test : manifests generate fmt vet setup-envtest # # Run tests.
62- KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
62+ KUBEBUILDER_ASSETS=" $( shell " $( ENVTEST) " use $( ENVTEST_K8S_VERSION) --bin-dir " $( LOCALBIN) " -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
6363
6464# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
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.
70- @command -v kind > /dev/null 2>&1 || { \
68+ KIND_CLUSTER ?= mapserver-operator-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
72+ @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+ @case " $$ ($( KIND) get clusters)" in \
77+ * " $( KIND_CLUSTER) " * ) \
78+ echo " Kind cluster '$( KIND_CLUSTER) ' already exists. Skipping creation." ;; \
79+ * ) \
80+ echo " Creating Kind cluster '$( KIND_CLUSTER) '..." ; \
81+ $(KIND ) create cluster --name $(KIND_CLUSTER ) ;; \
82+ esac
83+
84+ .PHONY : test-e2e
85+ test-e2e : setup-test-e2e manifests generate fmt vet # # Run the e2e tests. Expected an isolated environment using Kind.
86+ KIND=$(KIND ) KIND_CLUSTER=$(KIND_CLUSTER ) go test -tags=e2e ./test/e2e/ -v -ginkgo.v
87+ $(MAKE ) cleanup-test-e2e
88+
89+ .PHONY : cleanup-test-e2e
90+ cleanup-test-e2e : # # Tear down the Kind cluster used for e2e tests
91+ @$(KIND ) delete cluster --name $(KIND_CLUSTER )
7992
8093.PHONY : lint
8194lint : golangci-lint # # Run golangci-lint linter
82- $(GOLANGCI_LINT ) run
95+ " $( GOLANGCI_LINT) " run
8396
8497.PHONY : lint-fix
8598lint-fix : golangci-lint # # Run golangci-lint linter and perform fixes
86- $(GOLANGCI_LINT ) run --fix
99+ " $( GOLANGCI_LINT) " run --fix
87100
88101.PHONY : lint-config
89102lint-config : golangci-lint # # Verify golangci-lint linter configuration
90- $(GOLANGCI_LINT ) config verify
103+ " $( GOLANGCI_LINT) " config verify
91104
92105# #@ Build
93106
@@ -130,8 +143,8 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
130143.PHONY : build-installer
131144build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
132145 mkdir -p dist
133- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
134- $(KUSTOMIZE ) build config/default > dist/install.yaml
146+ cd config/manager && " $( KUSTOMIZE) " edit set image controller=${IMG}
147+ " $( KUSTOMIZE) " build config/default > dist/install.yaml
135148
136149# #@ Deployment
137150
@@ -141,44 +154,53 @@ endif
141154
142155.PHONY : install
143156install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
144- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
157+ @out=" $$ ( " $(KUSTOMIZE ) " build config/crd 2>/dev/null || true )" ; \
158+ if [ -n " $$ out" ]; then echo " $$ out" | " $( KUBECTL) " apply -f -; else echo " No CRDs to install; skipping." ; fi
145159
146160.PHONY : uninstall
147161uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
148- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
162+ @out=" $$ ( " $(KUSTOMIZE ) " build config/crd 2>/dev/null || true )" ; \
163+ if [ -n " $$ out" ]; then echo " $$ out" | " $( KUBECTL) " delete --ignore-not-found=$( ignore-not-found) -f -; else echo " No CRDs to delete; skipping." ; fi
149164
150165.PHONY : deploy
151166deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
152- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
153- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
167+ cd config/manager && " $( KUSTOMIZE) " edit set image controller=${IMG}
168+ " $( KUSTOMIZE) " build config/default | " $( KUBECTL) " apply -f -
154169
155170.PHONY : undeploy
156171undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
157- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
172+ " $( KUSTOMIZE) " build config/default | " $( KUBECTL) " delete --ignore-not-found=$(ignore-not-found ) -f -
158173
159174# #@ Dependencies
160175
161176# # Location to install dependencies to
162177LOCALBIN ?= $(shell pwd) /bin
163178$(LOCALBIN ) :
164- mkdir -p $(LOCALBIN )
179+ mkdir -p " $( LOCALBIN) "
165180
166181# # Tool Binaries
167182KUBECTL ?= kubectl
183+ KIND ?= kind
168184KUSTOMIZE ?= $(LOCALBIN ) /kustomize
169185CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
170186ENVTEST ?= $(LOCALBIN ) /setup-envtest
171187GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
172188
173189# # Tool Versions
174- KUSTOMIZE_VERSION ?= v5.5.0
175- CONTROLLER_TOOLS_VERSION ?= v0.17.2
190+ KUSTOMIZE_VERSION ?= v5.7.1
191+ CONTROLLER_TOOLS_VERSION ?= v0.19.0
192+
176193# ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
177- ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
194+ ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime) '; \
195+ [ -n "$$v" ] || { echo "Set ENVTEST_VERSION manually (controller-runtime replace has no tag) " >&2; exit 1; }; \
196+ printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
197+
178198# ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
179- ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
180- GOLANGCI_LINT_VERSION ?= v1.63.4
199+ ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api) '; \
200+ [ -n "$$v" ] || { echo "Set ENVTEST_K8S_VERSION manually (k8s.io/api replace has no tag) " >&2; exit 1; }; \
201+ printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
181202
203+ GOLANGCI_LINT_VERSION ?= v2.5.0
182204.PHONY : kustomize
183205kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
184206$(KUSTOMIZE ) : $(LOCALBIN )
@@ -192,7 +214,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
192214.PHONY : setup-envtest
193215setup-envtest : envtest # # Download the binaries required for ENVTEST in the local bin directory.
194216 @echo " Setting up envtest binaries for Kubernetes version $( ENVTEST_K8S_VERSION) ..."
195- @$(ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path || { \
217+ @" $( ENVTEST) " use $(ENVTEST_K8S_VERSION ) --bin-dir " $( LOCALBIN) " -p path || { \
196218 echo " Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
197219 exit 1; \
198220 }
@@ -205,20 +227,24 @@ $(ENVTEST): $(LOCALBIN)
205227.PHONY : golangci-lint
206228golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
207229$(GOLANGCI_LINT ) : $(LOCALBIN )
208- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
230+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2/ cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
209231
210232# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
211233# $1 - target path with name of binary
212234# $2 - package url which can be installed
213235# $3 - specific version of package
214236define go-install-tool
215- @[ -f "$(1 ) -$(3 ) " ] || { \
237+ @[ -f "$(1 ) -$(3 ) " ] && [ " $$( readlink -- " $( 1 ) " 2>/dev/null ) " = " $( 1 ) - $( 3 ) " ] || { \
216238set -e; \
217239package=$(2 ) @$(3 ) ;\
218240echo "Downloading $${package}" ;\
219- rm -f $(1 ) || true ;\
220- GOBIN=$(LOCALBIN ) go install $${package} ;\
221- mv $( 1 ) $(1 ) -$(3 ) ;\
241+ rm -f " $(1 ) " ;\
242+ GOBIN=" $(LOCALBIN ) " go install $${package} ;\
243+ mv " $( LOCALBIN ) / $$( basename " $( 1 ) ") " " $(1 ) -$(3 ) " ;\
222244} ;\
223- ln -sf $(1 ) -$(3 ) $(1 )
245+ ln -sf "$$(realpath "$(1 ) -$(3 ) ") " "$(1 ) "
246+ endef
247+
248+ define gomodver
249+ $(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1 ) 2>/dev/null)
224250endef
0 commit comments