Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cacaf4

Browse files
committed
Fix: make ENVTEST_K8S_VERSION respect go.mod replace directives
1 parent 30249eb commit 2cacaf4

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
@@ -269,7 +269,8 @@ CONTROLLER_TOOLS_VERSION ?= {{ .ControllerToolsVersion }}
269269
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
270270
ENVTEST_VERSION ?= $(shell go list -m -f "{{ "{{ .Version }}" }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
271271
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
272-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ "{{ .Version }}" }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
272+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
273+
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}}')
273274
GOLANGCI_LINT_VERSION ?= {{ .GolangciLintVersion }}
274275
275276
.PHONY: kustomize

testdata/project-v4-multigroup/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
190190
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
191191
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
192192
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
193-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
193+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
194+
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}}')
194195
GOLANGCI_LINT_VERSION ?= v2.4.0
195196

196197
.PHONY: kustomize

testdata/project-v4-with-plugins/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
190190
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
191191
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
192192
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
193-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
193+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
194+
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}}')
194195
GOLANGCI_LINT_VERSION ?= v2.4.0
195196

196197
.PHONY: kustomize

testdata/project-v4/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ CONTROLLER_TOOLS_VERSION ?= v0.19.0
190190
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
191191
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
192192
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
193-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
193+
ENVTEST_K8S_VERSION ?= $(shell go list -m k8s.io/api | \
194+
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}}')
194195
GOLANGCI_LINT_VERSION ?= v2.4.0
195196

196197
.PHONY: kustomize

0 commit comments

Comments
 (0)