1
+ IMAGE_BUILDER ?= podman
2
+
1
3
# VERSION defines the project version for the bundle.
2
4
# Update this value when you upgrade the version of your project.
3
5
# To re-generate a bundle for another specific version without changing the standard setup, you can:
@@ -37,13 +39,23 @@ IMAGE_TAG_BASE ?= quay.io/opdev/simple-demo-operator
37
39
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
38
40
BUNDLE_IMG ?= $(IMAGE_TAG_BASE ) -bundle:v$(VERSION )
39
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 ?= true
49
+ ifeq ($(USE_IMAGE_DIGESTS ) , true)
50
+ BUNDLE_GEN_FLAGS += --use-image-digests
51
+ endif
52
+
40
53
# Image URL to use all building/pushing image targets
41
54
IMG ?= $(IMAGE_TAG_BASE ) :$(VERSION )
42
55
IMGLATEST = $(IMAGE_TAG_BASE ) :latest
43
- # Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
44
- CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
56
+
45
57
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
46
- ENVTEST_K8S_VERSION = 1.21
58
+ ENVTEST_K8S_VERSION = 1.26.0
47
59
48
60
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
49
61
ifeq (,$(shell go env GOBIN) )
@@ -79,7 +91,7 @@ help: ## Display this help.
79
91
# #@ Development
80
92
81
93
manifests : controller-gen # # Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
82
- $(CONTROLLER_GEN ) $( CRD_OPTIONS ) rbac:roleName=manager-role webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
94
+ $(CONTROLLER_GEN ) rbac:roleName=manager-role crd webhook paths=" ./..." output:crd:artifacts:config=config/crd/bases
83
95
84
96
generate : controller-gen # # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
85
97
$(CONTROLLER_GEN ) object:headerFile=" hack/boilerplate.go.txt" paths=" ./..."
@@ -102,13 +114,13 @@ run: manifests generate fmt vet ## Run a controller from your host.
102
114
go run ./main.go
103
115
104
116
docker-build : # # Build docker image with the manager.
105
- docker build -t ${IMG} .
117
+ $( IMAGE_BUILDER ) build -t ${IMG} .
106
118
107
119
docker-push : # # Push docker image with the manager.
108
- docker push ${IMG}
120
+ $( IMAGE_BUILDER ) push ${IMG}
109
121
110
122
docker-tag-latest : # # tag as latest
111
- docker tag ${IMG} $(IMGLATEST )
123
+ $( IMAGE_BUILDER ) tag ${IMG} $(IMGLATEST )
112
124
113
125
docker-push-tag-latest : # # tag as latest
114
126
$(MAKE ) docker-push IMG=$(IMGLATEST )
@@ -129,52 +141,77 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
129
141
$(KUSTOMIZE ) build config/default | kubectl delete -f -
130
142
131
143
132
- CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
133
- controller-gen : # # Download controller-gen locally if necessary.
134
- $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
135
-
136
- KUSTOMIZE = $(shell pwd) /bin/kustomize
137
- kustomize : # # Download kustomize locally if necessary.
138
- $(call go-get-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/[email protected] )
139
-
140
- ENVTEST = $(shell pwd) /bin/setup-envtest
141
- envtest : # # Download envtest-setup locally if necessary.
142
- $(call go-get-tool,$(ENVTEST ) ,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
143
-
144
- DIGESTPINTOOL = $(shell pwd) /bin/pin-deploy-imgs-in-csv
145
- digestpintool : # # Download envtest-setup locally if necessary.
146
- $(call go-get-tool,$(DIGESTPINTOOL ) ,github.com/opdev/[email protected] )
144
+ # # Location to install dependencies to
145
+ LOCALBIN ?= $(shell pwd) /bin
146
+ $(LOCALBIN ) :
147
+ mkdir -p $(LOCALBIN )
148
+
149
+ # # Tool Binaries
150
+ KUSTOMIZE ?= $(LOCALBIN ) /kustomize
151
+ CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen
152
+ ENVTEST ?= $(LOCALBIN ) /setup-envtest
153
+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
154
+
155
+ # # Tool Versions
156
+ KUSTOMIZE_VERSION ?= v4.5.7
157
+ CONTROLLER_TOOLS_VERSION ?= v0.11.1
158
+ OPERATOR_SDK_VERSION ?= "v1.32.0"
159
+ KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
160
+ .PHONY : kustomize
161
+ kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
162
+ $(KUSTOMIZE ) : $(LOCALBIN )
163
+ @if test -x $(LOCALBIN ) /kustomize && ! $(LOCALBIN ) /kustomize version | grep -q $(KUSTOMIZE_VERSION ) ; then \
164
+ echo " $( LOCALBIN) /kustomize version is not expected $( KUSTOMIZE_VERSION) . Removing it before installing." ; \
165
+ rm -rf $(LOCALBIN ) /kustomize; \
166
+ fi
167
+ test -s $(LOCALBIN ) /kustomize || { curl -Ss $( KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $( subst v,,$( KUSTOMIZE_VERSION) ) $( LOCALBIN) ; }
168
+
169
+ .PHONY : controller-gen
170
+ controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
171
+ $(CONTROLLER_GEN ) : $(LOCALBIN )
172
+ test -s $(LOCALBIN ) /controller-gen && $(LOCALBIN ) /controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION ) || \
173
+ GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION )
174
+
175
+ .PHONY : envtest
176
+ envtest : $(ENVTEST ) # # Download envtest-setup locally if necessary.
177
+ $(ENVTEST ) : $(LOCALBIN )
178
+ test -s $(LOCALBIN ) /setup-envtest || GOBIN=$(LOCALBIN ) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
179
+
180
+ .PHONY : operator-sdk
181
+ OPERATOR_SDK ?= $(LOCALBIN ) /operator-sdk
182
+ operator-sdk : # # Download operator-sdk locally if necessary.
183
+ ifeq (,$(wildcard $(OPERATOR_SDK ) ) )
184
+ ifeq (, $(shell which operator-sdk 2>/dev/null) )
185
+ @{ \
186
+ set -e ;\
187
+ mkdir -p $(dir $(OPERATOR_SDK)) ;\
188
+ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
189
+ curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
190
+ chmod +x $(OPERATOR_SDK) ;\
191
+ }
192
+ else
193
+ OPERATOR_SDK = $(shell which operator-sdk)
194
+ endif
195
+ endif
147
196
148
- # go-get -tool will 'go get' any package $2 and install it to $1.
197
+ # go-install -tool will 'go get' any package $2 and install it to $1.
149
198
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
150
- define go-get -tool
199
+ define go-install -tool
151
200
@[ -f $(1 ) ] || { \
152
- set -e ;\
153
- TMP_DIR=$$(mktemp -d ) ;\
154
- cd $$TMP_DIR ;\
155
- go mod init tmp ;\
156
- echo "Downloading $(2 ) " ;\
157
- GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
158
- rm -rf $$TMP_DIR ;\
201
+ GOBIN=$(PROJECT_DIR ) /bin go install $(2 ) ;\
159
202
}
160
203
endef
161
204
162
- .PHONY : pin-ctrlr-digest
163
- pin-controller-digest : digestpintool
164
- $(DIGESTPINTOOL ) ./bundle/manifests/simple-demo-operator.clusterserviceversion.yaml
165
-
166
-
167
205
.PHONY : bundle
168
- bundle : manifests kustomize digestpintool # # Generate bundle manifests and metadata, then validate generated files.
206
+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
169
207
operator-sdk generate kustomize manifests -q
170
208
cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
171
- $(KUSTOMIZE ) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
172
-
173
- operator-sdk bundle validate ./bundle
209
+ $(KUSTOMIZE ) build config/manifests | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
210
+ $(OPERATOR_SDK ) bundle validate ./bundle
174
211
175
212
.PHONY : bundle-build
176
213
bundle-build : # # Build the bundle image.
177
- docker build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
214
+ $( IMAGE_BUILDER ) build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
178
215
179
216
.PHONY : bundle-push
180
217
bundle-push : # # Push the bundle image.
@@ -189,7 +226,7 @@ ifeq (,$(shell which opm 2>/dev/null))
189
226
set -e ;\
190
227
mkdir -p $(dir $(OPM)) ;\
191
228
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
192
- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1 /$${OS}-$${ARCH}-opm ;\
229
+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0 /$${OS}-$${ARCH}-opm ;\
193
230
chmod +x $(OPM) ;\
194
231
}
195
232
else
@@ -214,7 +251,7 @@ endif
214
251
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
215
252
.PHONY : catalog-build
216
253
catalog-build : opm # # Build a catalog image.
217
- $(OPM ) index add --container-tool docker --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
254
+ $(OPM ) index add --container-tool $( IMAGE_BUILDER ) --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
218
255
219
256
# Push the catalog image.
220
257
.PHONY : catalog-push
0 commit comments