Skip to content

Commit f7b6524

Browse files
restore go-get-tool function in Makefile and use to go install envtest and controller-gen
Signed-off-by: Michael Valdron <[email protected]>
1 parent ff11084 commit f7b6524

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Makefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ uninstall-cert:
189189
controller-gen: $(CONTROLLER_GEN)
190190
$(CONTROLLER_GEN): $(LOCALBIN)
191191
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
192-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
192+
$(call go-get-tool,sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION))
193193

194194
##@ Deployment
195195

@@ -219,7 +219,19 @@ $(KUSTOMIZE): $(LOCALBIN)
219219
.PHONY: envtest
220220
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
221221
$(ENVTEST): $(LOCALBIN)
222-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
222+
test -s $(LOCALBIN)/setup-envtest || $(call go-get-tool,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
223+
224+
# go-get-tool will 'go install' any package $2 and install it to $1.
225+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
226+
define go-get-tool
227+
set -e ;\
228+
TMP_DIR=$$(mktemp -d) ;\
229+
cd $$TMP_DIR ;\
230+
go mod init tmp ;\
231+
echo "Downloading $(1)" ;\
232+
GOBIN=$(LOCALBIN) go install $(1) ;\
233+
rm -rf $$TMP_DIR ;
234+
endef
223235

224236
# Generate bundle manifests and metadata, then validate generated files.
225237
.PHONY: bundle

0 commit comments

Comments
 (0)