@@ -46,6 +46,10 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
4646 BUNDLE_GEN_FLAGS += --use-image-digests
4747endif
4848
49+ # Set the Operator SDK version to use. By default, what is installed on the system is used.
50+ # This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51+ OPERATOR_SDK_VERSION ?= v1.31.0
52+
4953# Image URL to use all building/pushing image targets
5054DEFAULT_IMG ?= quay.io/openstack-k8s-operators/placement-operator:latest
5155IMG ?= $(DEFAULT_IMG )
@@ -60,7 +64,6 @@ GOBIN=$(shell go env GOBIN)
6064endif
6165
6266# Setting SHELL to bash allows bash commands to be executed by recipes.
63- # This is a requirement for 'setup-envtest.sh' in the test target.
6467# Options are set to exit when a recipe line exits non-zero or a piped command fails.
6568SHELL = /usr/bin/env bash -o pipefail
6669.SHELLFLAGS = -ec
@@ -190,15 +193,19 @@ CONTROLLER_TOOLS_VERSION ?= v0.11.1
190193
191194KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
192195.PHONY : kustomize
193- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
196+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
194197$(KUSTOMIZE ) : $(LOCALBIN )
195- rm -f $(LOCALBIN ) /kustomize || true
196- test -s $(LOCALBIN ) /kustomize || curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
198+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
199+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
200+ rm -rf $(LOCALBIN ) /kustomize; \
201+ fi
202+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
197203
198204.PHONY : controller-gen
199- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
205+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
200206$(CONTROLLER_GEN ) : $(LOCALBIN )
201- test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
207+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
208+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
202209
203210.PHONY : envtest
204211envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
@@ -210,12 +217,29 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
210217$(GINKGO ) : $(LOCALBIN )
211218 test -s $(LOCALBIN ) /ginkgo || GOBIN=$(LOCALBIN ) go install github.com/onsi/ginkgo/v2/ginkgo
212219
220+ .PHONY : operator-sdk
221+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
222+ operator-sdk : # # Download operator-sdk locally if necessary.
223+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
224+ ifeq (, $(shell which operator-sdk 2>/dev/null) )
225+ @{ \
226+ set -e ;\
227+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
228+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
229+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
230+ chmod +x $(OPERATOR_SDK) ;\
231+ }
232+ else
233+ OPERATOR_SDK = $(shell which operator-sdk)
234+ endif
235+ endif
236+
213237.PHONY : bundle
214- bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
215- operator-sdk generate kustomize manifests -q
238+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
239+ $( OPERATOR_SDK ) generate kustomize manifests -q
216240 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
217- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS )
218- operator-sdk bundle validate ./bundle
241+ $(KUSTOMIZE ) build config/manifests | $( OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
242+ $( OPERATOR_SDK ) bundle validate ./bundle --verbose
219243
220244.PHONY : bundle-build
221245bundle-build : # # Build the bundle image.
0 commit comments