CONTROLLeR_GeN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLeR_GeN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
KUSTOMIZe = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZe),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
eNVTeST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(eNVTeST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJeCT_DIR := $(shell dirname $(abspath $(lastword $(MAKeFILe_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJeCT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef