Skip to content

Commit 01c8abf

Browse files
Merge pull request #601 from yazug/standardize_makefile
update operator-sdk to use local/bin
2 parents 437be4d + 00c0c76 commit 01c8abf

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

Makefile

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
4646
BUNDLE_GEN_FLAGS += --use-image-digests
4747
endif
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
5054
DEFAULT_IMG ?= quay.io/openstack-k8s-operators/openstack-operator:latest
5155
IMG ?= $(DEFAULT_IMG)
@@ -62,7 +66,6 @@ GOBIN=$(shell go env GOBIN)
6266
endif
6367

6468
# Setting SHELL to bash allows bash commands to be executed by recipes.
65-
# This is a requirement for 'setup-envtest.sh' in the test target.
6669
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
6770
SHELL = /usr/bin/env bash -o pipefail
6871
.SHELLFLAGS = -ec
@@ -92,7 +95,7 @@ help: ## Display this help.
9295
.PHONY: manifests
9396
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
9497
$(CONTROLLER_GEN) rbac:roleName=manager-role crd$(CRDDESC_OVERRIDE) webhook paths="./..." output:crd:artifacts:config=config/crd/bases && \
95-
rm -f apis/bases/* && cp -a config/crd/bases apis/
98+
rm -f apis/bases/* && cp -a config/crd/bases apis/
9699

97100
.PHONY: generate
98101
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -214,14 +217,19 @@ CONTROLLER_TOOLS_VERSION ?= v0.11.1
214217

215218
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
216219
.PHONY: kustomize
217-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
220+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
218221
$(KUSTOMIZE): $(LOCALBIN)
219-
test -s $(LOCALBIN)/kustomize || curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
222+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
223+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
224+
rm -rf $(LOCALBIN)/kustomize; \
225+
fi
226+
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
220227

221228
.PHONY: controller-gen
222-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
229+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
223230
$(CONTROLLER_GEN): $(LOCALBIN)
224-
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
231+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
232+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
225233

226234
.PHONY: envtest
227235
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
@@ -233,13 +241,30 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary.
233241
$(GINKGO): $(LOCALBIN)
234242
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo
235243

244+
.PHONY: operator-sdk
245+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
246+
operator-sdk: ## Download operator-sdk locally if necessary.
247+
ifeq (,$(wildcard $(OPERATOR_SDK)))
248+
ifeq (, $(shell which operator-sdk 2>/dev/null))
249+
@{ \
250+
set -e ;\
251+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
252+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
253+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
254+
chmod +x $(OPERATOR_SDK) ;\
255+
}
256+
else
257+
OPERATOR_SDK = $(shell which operator-sdk)
258+
endif
259+
endif
260+
236261
.PHONY: bundle
237-
bundle: build manifests kustomize bundle-cache-extra-data ## Generate bundle manifests and metadata, then validate generated files.
238-
operator-sdk generate kustomize manifests -q
262+
bundle: build manifests kustomize bundle-cache-extra-data operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
263+
$(OPERATOR_SDK) generate kustomize manifests -q
239264
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
240-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
265+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
241266
cp dependencies.yaml ./bundle/metadata
242-
operator-sdk bundle validate ./bundle
267+
$(OPERATOR_SDK) bundle validate ./bundle
243268

244269
.PHONY: bundle-build
245270
bundle-build: bundle ## Build the bundle image.

0 commit comments

Comments
 (0)