diff --git a/Makefile b/Makefile index ab54733..4f87a02 100644 --- a/Makefile +++ b/Makefile @@ -189,7 +189,7 @@ uninstall-cert: controller-gen: $(CONTROLLER_GEN) $(CONTROLLER_GEN): $(LOCALBIN) test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ -GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) +$(call go-get-tool,sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)) ##@ Deployment @@ -219,7 +219,19 @@ $(KUSTOMIZE): $(LOCALBIN) .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) - test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + test -s $(LOCALBIN)/setup-envtest || $(call go-get-tool,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) + +# go-get-tool will 'go install' any package $2 and install it to $1. +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +define go-get-tool +set -e ;\ +TMP_DIR=$$(mktemp -d) ;\ +cd $$TMP_DIR ;\ +go mod init tmp ;\ +echo "Downloading $(1)" ;\ +GOBIN=$(LOCALBIN) go install $(1) ;\ +rm -rf $$TMP_DIR ; +endef # Generate bundle manifests and metadata, then validate generated files. .PHONY: bundle