@@ -157,47 +157,36 @@ $(LOCALBIN):
157157
158158# # Tool Binaries
159159KUBECTL ?= kubectl
160- KUSTOMIZE ?= $(LOCALBIN ) /kustomize- $( KUSTOMIZE_VERSION )
161- CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen- $( CONTROLLER_TOOLS_VERSION )
162- ENVTEST ?= $(LOCALBIN ) /setup-envtest- $( ENVTEST_VERSION )
163- GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint- $( GOLANGCI_LINT_VERSION )
160+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
161+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
162+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
163+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
164164
165165# # Tool Versions
166166KUSTOMIZE_VERSION ?= v5.3.0
167167CONTROLLER_TOOLS_VERSION ?= v0.14.0
168168ENVTEST_VERSION ?= latest
169169GOLANGCI_LINT_VERSION ?= v1.54.2
170170
171+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
172+
171173.PHONY : kustomize
172- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
173- $(KUSTOMIZE ) : $(LOCALBIN )
174- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
174+ kustomize : $(LOCALBIN )
175+ @if test -x $(KUSTOMIZE ) && ! $(KUSTOMIZE ) version | grep -q $(KUSTOMIZE_VERSION ) ; then \
176+ rm -f $(KUSTOMIZE ) ; \
177+ fi
178+ @test -x $(KUSTOMIZE ) || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
175179
176180.PHONY : controller-gen
177- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
178- $(CONTROLLER_GEN ) : $( LOCALBIN )
179- $( call go- install-tool, $( CONTROLLER_GEN ) , sigs.k8s.io/controller-tools/cmd/controller-gen, $(CONTROLLER_TOOLS_VERSION ) )
181+ controller-gen : $(LOCALBIN )
182+ @test -x $(CONTROLLER_GEN ) && $( CONTROLLER_GEN ) --version | grep -q $( CONTROLLER_TOOLS_VERSION ) || \
183+ GOBIN= $( LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@ $(CONTROLLER_TOOLS_VERSION )
180184
181185.PHONY : envtest
182- envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
183- $(ENVTEST ) : $(LOCALBIN )
184- $(call go-install-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION ) )
186+ envtest : $(LOCALBIN )
187+ @test -x $(ENVTEST ) || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION )
185188
186189.PHONY : golangci-lint
187- golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
188- $(GOLANGCI_LINT ) : $(LOCALBIN )
189- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
190-
191- # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
192- # $1 - target path with name of binary (ideally with version)
193- # $2 - package url which can be installed
194- # $3 - specific version of package
195- define go-install-tool
196- @[ -f $(1 ) ] || { \
197- set -e; \
198- package=$(2 ) @$(3 ) ;\
199- echo "Downloading $${package}" ;\
200- GOBIN=$(LOCALBIN ) go install $${package} ;\
201- mv "$$(echo "$(1 ) " | sed "s/-$(3 ) $$//" ) " $(1 ) ;\
202- }
203- endef
190+ golangci-lint : $(LOCALBIN )
191+ @test -x $(GOLANGCI_LINT ) && $(GOLANGCI_LINT ) version | grep -q $(GOLANGCI_LINT_VERSION ) || \
192+ GOBIN=$(LOCALBIN ) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION )
0 commit comments