@@ -268,12 +268,18 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
268268## Tool Versions
269269KUSTOMIZE_VERSION ?= {{ .KustomizeVersion }}
270270CONTROLLER_TOOLS_VERSION ?= {{ .ControllerToolsVersion }}
271+
271272#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
272- ENVTEST_VERSION ?= $(shell go list -m -f "{{ "{{ .Version }}" }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
273+ ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; \
274+ [ -n "$$v" ] || { echo "Set ENVTEST_VERSION manually (controller-runtime replace has no tag)" >&2; exit 1; }; \
275+ printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
276+
273277#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
274- ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ "{{ .Version }}" }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
275- GOLANGCI_LINT_VERSION ?= {{ .GolangciLintVersion }}
278+ ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api)'; \
279+ [ -n "$$v" ] || { echo "Set ENVTEST_K8S_VERSION manually (k8s.io/api replace has no tag)" >&2; exit 1; }; \
280+ printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
276281
282+ GOLANGCI_LINT_VERSION ?= {{ .GolangciLintVersion }}
277283.PHONY: kustomize
278284kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
279285$(KUSTOMIZE): $(LOCALBIN)
@@ -317,4 +323,8 @@ mv "$(LOCALBIN)/$$(basename "$(1)")" "$(1)-$(3)" ;\
317323} ;\
318324ln -sf "$$(realpath "$(1)-$(3)")" "$(1)"
319325endef
326+
327+ define gomodver
328+ $(shell go list -m -f '{{"{{"}}if .Replace{{"}}"}}{{"{{"}}.Replace.Version{{"}}"}}{{"{{"}}else{{"}}"}}{{"{{"}}.Version{{"}}"}}{{"{{"}}end{{"}}"}}' $(1) 2>/dev/null)
329+ endef
320330`
0 commit comments