Skip to content

Commit 01a237b

Browse files
committed
Adapt version extraction used by the makefiles from newer kubebuilder versions
Reading dep versions from the go mods instead of maininting them in parallel Signed-off-by: Jannik Hollenbach <jannik.hollenbach@iteratec.com>
1 parent 41cba94 commit 01a237b

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

auto-discovery/cloud-aws/Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ IMG ?= auto-discovery-cloud-aws
1313
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)
1414

1515
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
16-
ENVTEST_K8S_VERSION = 1.33.0
16+
# Derived automatically from k8s.io/api in go.mod - updated by renovate via go.mod.
17+
ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api)'; printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
1718

1819
# ENVTEST_VERSION refers to the version of setup-envtest binary.
19-
ENVTEST_VERSION ?= release-0.21
20+
# Derived automatically from sigs.k8s.io/controller-runtime in go.mod - updated by renovate via go.mod.
21+
ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
2022

2123
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set).
2224
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
@@ -127,7 +129,7 @@ $(LOCALBIN):
127129
mkdir -p $(LOCALBIN)
128130

129131
## Tool Binaries
130-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
132+
ENVTEST ?= $(LOCALBIN)/setup-envtest
131133

132134
.PHONY: envtest
133135
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
@@ -157,3 +159,6 @@ GOBIN=$(LOCALBIN) go install $${package} ;\
157159
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
158160
}
159161
endef
162+
define gomodver
163+
$(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1) 2>/dev/null)
164+
endef

auto-discovery/kubernetes/Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ IMG ?= auto-discovery-kubernetes
1313
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)
1414

1515
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
16-
ENVTEST_K8S_VERSION = 1.33.0
16+
# Derived automatically from k8s.io/api in go.mod - updated by renovate via go.mod.
17+
ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api)'; printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
1718

1819
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set).
1920
# IMPORTANT: The body of conditionals MUST not be indented! Indentation result in
@@ -142,11 +143,12 @@ $(LOCALBIN):
142143

143144
## Tool Binaries
144145
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
145-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
146+
ENVTEST ?= $(LOCALBIN)/setup-envtest
146147

147148
## Tool Versions
148149
CONTROLLER_TOOLS_VERSION ?= v0.18.0
149-
ENVTEST_VERSION ?= release-0.21
150+
# Derived automatically from sigs.k8s.io/controller-runtime in go.mod - updated by renovate via go.mod.
151+
ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
150152

151153
.PHONY: controller-gen
152154
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
@@ -171,3 +173,6 @@ GOBIN=$(LOCALBIN) go install $${package} ;\
171173
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
172174
}
173175
endef
176+
define gomodver
177+
$(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1) 2>/dev/null)
178+
endef

operator/Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ PROJECT_DIR=..
1111
IMG_NS ?= securecodebox
1212

1313
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
14-
ENVTEST_K8S_VERSION = 1.33.0
14+
# Derived automatically from k8s.io/api in go.mod - updated by renovate via go.mod.
15+
ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api)'; printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
1516

1617
# Image URL to use all building/pushing image targets for the operator
1718
OPERATOR_IMG ?= operator
@@ -175,11 +176,12 @@ $(LOCALBIN):
175176

176177
## Tool Binaries
177178
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
178-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
179+
ENVTEST ?= $(LOCALBIN)/setup-envtest
179180

180181
## Tool Versions
181182
CONTROLLER_TOOLS_VERSION ?= v0.18.0
182-
ENVTEST_VERSION ?= release-0.21
183+
# Derived automatically from sigs.k8s.io/controller-runtime in go.mod - updated by renovate via go.mod.
184+
ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
183185

184186
.PHONY: controller-gen
185187
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
@@ -204,3 +206,6 @@ GOBIN=$(LOCALBIN) go install $${package} ;\
204206
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
205207
}
206208
endef
209+
define gomodver
210+
$(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1) 2>/dev/null)
211+
endef

0 commit comments

Comments
 (0)