@@ -39,6 +39,17 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
39
39
# redhat.io/patch-operator-bundle:$VERSION and redhat.io/patch-operator-catalog:$VERSION.
40
40
IMAGE_TAG_BASE ?= quay.io/redhat-cop/$(OPERATOR_NAME )
41
41
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
+
42
53
# BUNDLE_IMG defines the image:tag used for the bundle.
43
54
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
44
55
BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
@@ -48,7 +59,7 @@ IMG ?= controller:latest
48
59
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
49
60
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
50
61
# 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
52
63
53
64
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
54
65
ifeq (,$(shell go env GOBIN) )
63
74
SHELL = /usr/bin/env bash -o pipefail
64
75
.SHELLFLAGS = -ec
65
76
77
+ .PHONY : all
66
78
all : build
67
79
68
80
# #@ General
@@ -78,23 +90,29 @@ all: build
78
90
# More info on the awk command:
79
91
# http://linuxcommand.org/lc3_adv_awk.php
80
92
93
+ .PHONY : help
81
94
help : # # Display this help.
82
95
@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
96
84
97
# #@ Development
85
98
99
+ .PHONY : manifests
86
100
manifests : 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
88
102
103
+ .PHONY : generate
89
104
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
90
105
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
91
106
107
+ .PHONY : fmt
92
108
fmt : # # Run go fmt against code.
93
109
go fmt ./...
94
110
111
+ .PHONY : vet
95
112
vet : # # Run go vet against code.
96
113
go vet ./...
97
114
115
+ .PHONY : test
98
116
test : manifests generate fmt vet envtest # # Run tests.
99
117
KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) -p path) " go test ./... -coverprofile cover.out
100
118
@@ -107,65 +125,79 @@ kind-setup: kind kubectl helm
107
125
108
126
# #@ Build
109
127
128
+ .PHONY : build
110
129
build : generate fmt vet # # Build manager binary.
111
130
go build -o bin/manager main.go
112
131
132
+ .PHONY : run
113
133
run : manifests generate fmt vet # # Run a controller from your host.
114
134
go run ./main.go
115
135
136
+ .PHONY : docker-build
116
137
docker-build : test # # Build docker image with the manager.
117
138
docker build -t ${IMG} .
118
139
140
+ .PHONY : docker-push
119
141
docker-push : # # Push docker image with the manager.
120
142
docker push ${IMG}
121
143
122
144
# #@ Deployment
123
145
146
+ ifndef ignore-not-found
147
+ ignore-not-found = false
148
+ endif
149
+
150
+ .PHONY : install
124
151
install : manifests kustomize kubectl # # Install CRDs into the K8s cluster specified in ~/.kube/config.
125
152
$(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
126
153
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 -
129
157
158
+ .PHONY : deploy
130
159
deploy : manifests kustomize kubectl # # Deploy controller to the K8s cluster specified in ~/.kube/config.
131
160
cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
132
161
$(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
133
162
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
136
175
176
+ KUSTOMIZE_VERSION ?= v3.8.7
177
+ CONTROLLER_TOOLS_VERSION ?= v0.9.0
137
178
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] )
141
179
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 )
145
184
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 )
149
190
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
163
195
164
196
.PHONY : bundle
165
197
bundle : 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
167
199
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 )
169
201
operator-sdk bundle validate ./bundle
170
202
171
203
.PHONY : bundle-build
@@ -185,7 +217,7 @@ ifeq (,$(shell which opm 2>/dev/null))
185
217
set -e ;\
186
218
mkdir -p $(dir $(OPM)) ;\
187
219
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 ;\
189
221
chmod +x $(OPM) ;\
190
222
}
191
223
else
@@ -218,6 +250,7 @@ catalog-push: ## Push a catalog image.
218
250
$(MAKE ) docker-push IMG=$(CATALOG_IMG )
219
251
220
252
# Generate helm chart
253
+ .PHONY : helmchart
221
254
helmchart : kustomize helm
222
255
mkdir -p ./charts/${OPERATOR_NAME} /templates
223
256
mkdir -p ./charts/${OPERATOR_NAME} /crds
@@ -233,11 +266,12 @@ helmchart: kustomize helm
233
266
echo {{ end }} >> ./charts/${OPERATOR_NAME} /templates/monitoring.coreos.com_v1_servicemonitor_${OPERATOR_NAME} -controller-manager-metrics-monitor.yaml
234
267
$(HELM ) lint ./charts/${OPERATOR_NAME}
235
268
236
- helmchart-repo : helmchart
269
+ .PHONY : helmchart-repo
237
270
mkdir -p ${HELM_REPO_DEST} /${OPERATOR_NAME}
238
271
$(HELM ) package -d ${HELM_REPO_DEST} /${OPERATOR_NAME} ./charts/${OPERATOR_NAME}
239
272
$(HELM ) repo index --url ${CHART_REPO_URL} ${HELM_REPO_DEST}
240
273
274
+ .PHONY : helmchart-repo-push
241
275
helmchart-repo-push : helmchart-repo
242
276
git -C ${HELM_REPO_DEST} add .
243
277
git -C ${HELM_REPO_DEST} status
0 commit comments