@@ -39,6 +39,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
3939# redhat.io/patch-operator-bundle:$VERSION and redhat.io/patch-operator-catalog:$VERSION.
4040IMAGE_TAG_BASE ?= quay.io/redhat-cop/$(OPERATOR_NAME )
4141
42+ # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
43+ BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
44+
45+ # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
46+ # You can enable this value if you would like to use SHA Based Digests
47+ # To enable set flag to true
48+ USE_IMAGE_DIGESTS ?= false
49+ ifeq ($(USE_IMAGE_DIGESTS ) , true)
50+ BUNDLE_GEN_FLAGS += --use-image-digests
51+ endif
52+
4253# BUNDLE_IMG defines the image:tag used for the bundle.
4354# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
4455BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
@@ -48,7 +59,7 @@ IMG ?= controller:latest
4859# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
4960CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
5061# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
51- ENVTEST_K8S_VERSION = 1.21
62+ ENVTEST_K8S_VERSION = 1.24.1
5263
5364# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5465ifeq (,$(shell go env GOBIN) )
6374SHELL = /usr/bin/env bash -o pipefail
6475.SHELLFLAGS = -ec
6576
77+ .PHONY : all
6678all : build
6779
6880# #@ General
@@ -78,23 +90,29 @@ all: build
7890# More info on the awk command:
7991# http://linuxcommand.org/lc3_adv_awk.php
8092
93+ .PHONY : help
8194help : # # Display this help.
8295 @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 )
8396
8497# #@ Development
8598
99+ .PHONY : manifests
86100manifests : 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
101+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
88102
103+ .PHONY : generate
89104generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
90105 $(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
91106
107+ .PHONY : fmt
92108fmt : # # Run go fmt against code.
93109 go fmt ./...
94110
111+ .PHONY : vet
95112vet : # # Run go vet against code.
96113 go vet ./...
97114
115+ .PHONY : test
98116test : manifests generate fmt vet envtest # # Run tests.
99117 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
100118
@@ -107,65 +125,79 @@ kind-setup: kind kubectl helm
107125
108126# #@ Build
109127
128+ .PHONY : build
110129build : generate fmt vet # # Build manager binary.
111130 go build -o bin/manager main.go
112131
132+ .PHONY : run
113133run : manifests generate fmt vet # # Run a controller from your host.
114134 go run ./main.go
115135
136+ .PHONY : docker-build
116137docker-build : test # # Build docker image with the manager.
117138 docker build -t ${IMG} .
118139
140+ .PHONY : docker-push
119141docker-push : # # Push docker image with the manager.
120142 docker push ${IMG}
121143
122144# #@ Deployment
123145
146+ ifndef ignore-not-found
147+ ignore-not-found = false
148+ endif
149+
150+ .PHONY : install
124151install : manifests kustomize kubectl # # Install CRDs into the K8s cluster specified in ~/.kube/config.
125152 $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
126153
127- uninstall : manifests kustomize kubectl # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
128- $(KUSTOMIZE ) build config/crd | $(KUBECTL ) delete -f -
154+ .PHONY : uninstall
155+ uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
156+ $(KUSTOMIZE ) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
129157
158+ .PHONY : deploy
130159deploy : manifests kustomize kubectl # # Deploy controller to the K8s cluster specified in ~/.kube/config.
131160 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
132161 $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
133162
134- undeploy : kustomize kubectl # # Undeploy controller from the K8s cluster specified in ~/.kube/config.
135- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete -f -
163+ .PHONY : undeploy
164+ undeploy : # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
165+ $(KUSTOMIZE ) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found ) -f -
166+
167+ LOCALBIN ?= $(shell pwd) /bin
168+ $(LOCALBIN ) :
169+ mkdir -p $(LOCALBIN )
170+
171+ # # Tool Binaries
172+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
173+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
174+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
136175
176+ KUSTOMIZE_VERSION ?= v3.8.7
177+ CONTROLLER_TOOLS_VERSION ?= v0.9.0
137178
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/[email protected] ) 141179
142- KUSTOMIZE = $(shell pwd) /bin/kustomize
143- kustomize : # # Download kustomize locally if necessary.
144- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] ) 180+ .PHONY : controller-gen
181+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
182+ $(CONTROLLER_GEN ) : $(LOCALBIN )
183+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
145184
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)
185+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
186+ .PHONY : kustomize
187+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
188+ $(KUSTOMIZE ) : $(LOCALBIN )
189+ curl -s $(KUSTOMIZE_INSTALL_SCRIPT ) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION ) ) $(LOCALBIN )
149190
150- # go-get-tool will 'go get' any package $2 and install it to $1.
151- PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
152- define go-get-tool
153- @[ -f $(1 ) ] || { \
154- set -e ;\
155- TMP_DIR=$$(mktemp -d ) ;\
156- cd $$TMP_DIR ;\
157- go mod init tmp ;\
158- echo "Downloading $(2 ) " ;\
159- GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
160- rm -rf $$TMP_DIR ;\
161- }
162- endef
191+ .PHONY : envtest
192+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
193+ $(ENVTEST ) : $(LOCALBIN )
194+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
163195
164196.PHONY : bundle
165197bundle : manifests kustomize # # Generate bundle manifests and metadata, then validate generated files.
166- operator-sdk generate kustomize manifests -q
198+ operator-sdk generate kustomize manifests --interactive=false - q
167199 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 )
200+ $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle $( BUNDLE_GEN_FLAGS )
169201 operator-sdk bundle validate ./bundle
170202
171203.PHONY : bundle-build
@@ -185,7 +217,7 @@ ifeq (,$(shell which opm 2>/dev/null))
185217 set -e ;\
186218 mkdir -p $(dir $(OPM)) ;\
187219 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 ;\
220+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0 /$${OS}-$${ARCH}-opm ;\
189221 chmod +x $(OPM) ;\
190222 }
191223else
@@ -218,6 +250,7 @@ catalog-push: ## Push a catalog image.
218250 $(MAKE ) docker-push IMG=$(CATALOG_IMG )
219251
220252# Generate helm chart
253+ .PHONY : helmchart
221254helmchart : kustomize helm
222255 mkdir -p ./charts/${OPERATOR_NAME} /templates
223256 mkdir -p ./charts/${OPERATOR_NAME} /crds
@@ -233,11 +266,12 @@ helmchart: kustomize helm
233266 echo {{ end }} >> ./charts/${OPERATOR_NAME} /templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME} -controller-manager-metrics-monitor.yaml
234267 $(HELM ) lint ./charts/${OPERATOR_NAME}
235268
236- helmchart-repo : helmchart
269+ .PHONY : helmchart-repo
237270 mkdir -p ${HELM_REPO_DEST} /${OPERATOR_NAME}
238271 $(HELM ) package -d ${HELM_REPO_DEST} /${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
239272 $(HELM ) repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
240273
274+ .PHONY : helmchart-repo-push
241275helmchart-repo-push : helmchart-repo
242276 git -C ${HELM_REPO_DEST} add .
243277 git -C ${HELM_REPO_DEST} status
0 commit comments