@@ -87,25 +87,31 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
87
87
undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
88
88
$(KUSTOMIZE ) build config/default | kubectl delete -f -
89
89
90
-
91
- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
92
- controller-gen : # # Download controller-gen locally if necessary.
93
- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
94
-
95
- KUSTOMIZE = $(shell pwd) /bin/kustomize
96
- kustomize : # # Download kustomize locally if necessary.
97
- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
98
-
99
- # go-get-tool will 'go get' any package $2 and install it to $1.
100
- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
101
- define go-get-tool
102
- @[ -f $(1 ) ] || { \
103
- set -e ;\
104
- TMP_DIR=$$(mktemp -d ) ;\
105
- cd $$TMP_DIR ;\
106
- go mod init tmp ;\
107
- echo "Downloading $(2 ) " ;\
108
- GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
109
- rm -rf $$TMP_DIR ;\
110
- }
111
- endef
90
+ # # Location to install dependencies to
91
+ LOCALBIN ?= $(shell pwd) /bin
92
+ $(LOCALBIN ) :
93
+ mkdir -p $(LOCALBIN )
94
+
95
+ # # Tool Binaries
96
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
97
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
98
+
99
+ # # Tool Versions
100
+ KUSTOMIZE_VERSION ?= v3.8.7
101
+ CONTROLLER_TOOLS_VERSION ?= v0.4.1
102
+
103
+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
104
+ .PHONY : kustomize
105
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
106
+ $(KUSTOMIZE ) : $(LOCALBIN )
107
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
108
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
109
+ rm -rf $(LOCALBIN ) /kustomize; \
110
+ fi
111
+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) --output install_kustomize.sh && bash install_kustomize.sh $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; rm install_kustomize.sh; }
112
+
113
+ .PHONY : controller-gen
114
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
115
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
116
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
117
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
0 commit comments