11CHART_REPO_URL ?= http://example.com
22HELM_REPO_DEST ?= /tmp/gh-pages
33OPERATOR_NAME ?=$(shell basename -z `pwd`)
4- HELM_VERSION ?= v3.8.0
5- KIND_VERSION ?= v0.11.1
6- KUBECTL_VERSION ?= v1.21.1
7- VAULT_VERSION ?= 1.9.3
4+ HELM_VERSION ?= v3.11.0
5+ KIND_VERSION ?= v0.20.0
6+ KUBECTL_VERSION ?= v1.27.3
7+ K8S_MAJOR_VERSION ?= 1.27
8+ KUSTOMIZE_VERSION ?= v3.8.7
9+ CONTROLLER_TOOLS_VERSION ?= v0.11.1
10+ # Set the Operator SDK version to use. By default, what is installed on the system is used.
11+ # This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
12+ OPERATOR_SDK_VERSION ?= v1.31.0
13+ # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
14+ ENVTEST_K8S_VERSION ?= 1.26.0
815
916# VERSION defines the project version for the bundle.
1017# Update this value when you upgrade the version of your project.
@@ -78,23 +85,28 @@ all: build
7885# More info on the awk command:
7986# http://linuxcommand.org/lc3_adv_awk.php
8087
88+ .PHONY : help
8189help : # # Display this help.
8290 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
83-
8491# #@ Development
8592
93+ .PHONY : manifests
8694manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
87- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
95+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
8896
97+ .PHONY : generate
8998generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
9099 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
91100
101+ .PHONY : fmt
92102fmt : # # Run go fmt against code.
93103 go fmt ./...
94104
105+ .PHONY : vet
95106vet : # # Run go vet against code.
96107 go vet ./...
97108
109+ .PHONY : test
98110test : manifests generate fmt vet envtest # # Run tests.
99111 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
100112
@@ -134,18 +146,35 @@ deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster spec
134146undeploy : kustomize kubectl # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
135147 $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete -f -
136148
149+ LOCALBIN ?= $(shell pwd) /bin
150+ $(LOCALBIN ) :
151+ mkdir -p $(LOCALBIN )
152+
153+ # # Tool Binaries
154+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
155+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
156+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
137157
138- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
139- controller-gen : # # Download controller-gen locally if necessary.
140- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1)
141158
142- KUSTOMIZE = $(shell pwd) /bin/kustomize
143- kustomize : # # Download kustomize locally if necessary.
144- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
145159
146- ENVTEST = $(shell pwd) /bin/setup-envtest
147- envtest : # # Download envtest-setup locally if necessary.
148- $(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
160+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
161+ .PHONY : kustomize
162+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
163+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
164+ $(KUSTOMIZE ) : $(LOCALBIN )
165+ test -s $(LOCALBIN ) /kustomize || { curl -s $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
166+
167+ .PHONY : controller-gen
168+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
169+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
170+ $(CONTROLLER_GEN ) : $(LOCALBIN )
171+ test -s $(LOCALBIN ) /controller-gen || echo " Downloading controller-gen to ${CONTROLLER_GEN} ..." && GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
172+
173+ .PHONY : envtest
174+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
175+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
176+ $(ENVTEST ) : $(LOCALBIN )
177+ test -s $(LOCALBIN ) /setup-envtest || echo " Downloading setup-envtest to ${ENVTEST} ..." && GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
149178
150179# go-get-tool will 'go get' any package $2 and install it to $1.
151180PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
@@ -162,11 +191,11 @@ rm -rf $$TMP_DIR ;\
162191endef
163192
164193.PHONY : bundle
165- bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
166- operator-sdk generate kustomize manifests -q
194+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
195+ $( OPERATOR_SDK ) generate kustomize manifests --interactive=false -q
167196 cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
168- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $( VERSION ) $( BUNDLE_METADATA_OPTS )
169- operator-sdk bundle validate ./bundle
197+ $(KUSTOMIZE ) build config/manifests | $( OPERATOR_SDK ) generate bundle $( BUNDLE_GEN_FLAGS )
198+ $( OPERATOR_SDK ) bundle validate ./bundle
170199
171200.PHONY : bundle-build
172201bundle-build : # # Build the bundle image.
@@ -177,15 +206,15 @@ bundle-push: ## Push the bundle image.
177206 $(MAKE ) docker-push IMG=$(BUNDLE_IMG )
178207
179208.PHONY : opm
180- OPM = ./bin /opm
209+ OPM ?= $( LOCALBIN ) /opm
181210opm : # # Download opm locally if necessary.
182211ifeq (,$(wildcard $(OPM ) ) )
183212ifeq (,$(shell which opm 2>/dev/null) )
184213 @{ \
185214 set -e ;\
186215 mkdir -p $(dir $(OPM)) ;\
187216 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
188- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1 /$${OS}-$${ARCH}-opm ;\
217+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0 /$${OS}-$${ARCH}-opm ;\
189218 chmod +x $(OPM) ;\
190219 }
191220else
@@ -308,3 +337,21 @@ else
308337HELM = $(shell which helm)
309338endif
310339endif
340+
341+ .PHONY : operator-sdk
342+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
343+ operator-sdk : # # Download operator-sdk locally if necessary.
344+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
345+ @{ \
346+ set -e ;\
347+ echo "Downloading operator-sdk to $(OPERATOR_SDK)..." ;\
348+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
349+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
350+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
351+ chmod +x $(OPERATOR_SDK) ;\
352+ }
353+ endif
354+
355+ .PHONY : clean
356+ clean :
357+ rm -rf $(LOCALBIN ) ./bundle ./bundle-* ./charts
0 commit comments