@@ -46,6 +46,10 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
46
46
BUNDLE_GEN_FLAGS += --use-image-digests
47
47
endif
48
48
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
+
49
53
# Image URL to use all building/pushing image targets
50
54
DEFAULT_IMG ?= quay.io/openstack-k8s-operators/mariadb-operator:latest
51
55
IMG ?= $(DEFAULT_IMG )
@@ -60,7 +64,6 @@ GOBIN=$(shell go env GOBIN)
60
64
endif
61
65
62
66
# 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.
64
67
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
65
68
SHELL = /usr/bin/env bash -o pipefail
66
69
.SHELLFLAGS = -ec
@@ -199,27 +202,48 @@ CONTROLLER_TOOLS_VERSION ?= v0.11.1
199
202
200
203
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
201
204
.PHONY : kustomize
202
- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
205
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
203
206
$(KUSTOMIZE ) : $(LOCALBIN )
204
- rm -f $(LOCALBIN ) /kustomize || true
205
- test -s $(LOCALBIN ) /kustomize || curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
207
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
208
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
209
+ rm -rf $(LOCALBIN ) /kustomize; \
210
+ fi
211
+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
206
212
207
213
.PHONY : controller-gen
208
- controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
214
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
209
215
$(CONTROLLER_GEN ) : $(LOCALBIN )
210
- test -s $(LOCALBIN ) /controller-gen || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
216
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
217
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
211
218
212
219
.PHONY : envtest
213
220
envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
214
221
$(ENVTEST ) : $(LOCALBIN )
215
222
test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
216
223
224
+ .PHONY : operator-sdk
225
+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
226
+ operator-sdk : # # Download operator-sdk locally if necessary.
227
+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
228
+ ifeq (, $(shell which operator-sdk 2>/dev/null) )
229
+ @{ \
230
+ set -e ;\
231
+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
232
+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
233
+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
234
+ chmod +x $(OPERATOR_SDK) ;\
235
+ }
236
+ else
237
+ OPERATOR_SDK = $(shell which operator-sdk)
238
+ endif
239
+ endif
240
+
217
241
.PHONY : bundle
218
- bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
219
- operator-sdk generate kustomize manifests -q
242
+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
243
+ $( OPERATOR_SDK ) generate kustomize manifests -q
220
244
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
221
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS )
222
- operator-sdk bundle validate ./bundle
245
+ $(KUSTOMIZE ) build config/manifests | $( OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
246
+ $( OPERATOR_SDK ) bundle validate ./bundle
223
247
224
248
.PHONY : bundle-build
225
249
bundle-build : # # Build the bundle image.
0 commit comments