Skip to content

Commit 71426c2

Browse files
committed
Fix: make ENVTEST_K8S_VERSION respect go.mod replace directives
1 parent 3fd0419 commit 71426c2

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ CONTROLLER_TOOLS_VERSION ?= {{ .ControllerToolsVersion }}
271271
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
272272
ENVTEST_VERSION ?= $(shell go list -m -f "{{ "{{ .Version }}" }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
273273
#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}')
274+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
275+
awk '{if ($$NF ~ /^v[0-9]/) {gsub(/^v/,"",$$NF); split($$NF,v,"."); major=v[1]; minor=v[2]; if (major==0) major=1; printf "%d.%d", major, minor} else {print "Error: Cannot detect version. Set ENVTEST_K8S_VERSION manually." > "/dev/stderr"; exit 1}}')
275276
GOLANGCI_LINT_VERSION ?= {{ .GolangciLintVersion }}
276277
277278
.PHONY: kustomize

testdata/project-v4-multigroup/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
192192
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
193193
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
194194
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
195-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
195+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
196+
awk '{if ($$NF ~ /^v[0-9]/) {gsub(/^v/,"",$$NF); split($$NF,v,"."); major=v[1]; minor=v[2]; if (major==0) major=1; printf "%d.%d", major, minor} else {print "Error: Cannot detect version. Set ENVTEST_K8S_VERSION manually." > "/dev/stderr"; exit 1}}')
196197
GOLANGCI_LINT_VERSION ?= v2.4.0
197198

198199
.PHONY: kustomize

testdata/project-v4-with-plugins/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
192192
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
193193
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
194194
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
195-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
195+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
196+
awk '{if ($$NF ~ /^v[0-9]/) {gsub(/^v/,"",$$NF); split($$NF,v,"."); major=v[1]; minor=v[2]; if (major==0) major=1; printf "%d.%d", major, minor} else {print "Error: Cannot detect version. Set ENVTEST_K8S_VERSION manually." > "/dev/stderr"; exit 1}}')
196197
GOLANGCI_LINT_VERSION ?= v2.4.0
197198

198199
.PHONY: kustomize

testdata/project-v4/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
192192
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
193193
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
194194
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
195-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
195+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
196+
awk '{if ($$NF ~ /^v[0-9]/) {gsub(/^v/,"",$$NF); split($$NF,v,"."); major=v[1]; minor=v[2]; if (major==0) major=1; printf "%d.%d", major, minor} else {print "Error: Cannot detect version. Set ENVTEST_K8S_VERSION manually." > "/dev/stderr"; exit 1}}')
196197
GOLANGCI_LINT_VERSION ?= v2.4.0
197198

198199
.PHONY: kustomize

0 commit comments

Comments
 (0)