@@ -28,8 +28,8 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
28
28
# This variable is used to construct full image tags for bundle and catalog images.
29
29
#
30
30
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31
- # sigstore.dev/ model-validation-operator-bundle:$VERSION and sigstore.dev /model-validation-operator-catalog:$VERSION.
32
- IMAGE_TAG_BASE ?= sigstore.dev /model-validation-operator
31
+ # ghcr.io/sigstore/ model-validation-operator-bundle:$VERSION and ghcr.io/sigstore /model-validation-operator-catalog:$VERSION.
32
+ IMAGE_TAG_BASE ?= ghcr.io/sigstore /model-validation-operator
33
33
34
34
# BUNDLE_IMG defines the image:tag used for the bundle.
35
35
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
@@ -38,6 +38,9 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
38
38
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39
39
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION ) $(BUNDLE_METADATA_OPTS )
40
40
41
+ # BUNDLE_OVERLAY defines which overlay to use for bundle generation (e.g. make bundle BUNDLE_OVERLAY=production)
42
+ BUNDLE_OVERLAY ?= olm
43
+
41
44
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42
45
# You can enable this value if you would like to use SHA Based Digests
43
46
# To enable set flag to true
48
51
49
52
# Set the Operator SDK version to use. By default, what is installed on the system is used.
50
53
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51
- OPERATOR_SDK_VERSION ?= v1.40.0
54
+ OPERATOR_SDK_VERSION ?= v1.41.1
52
55
# Image URL to use all building/pushing image targets
53
56
IMG ?= controller:latest
54
57
64
67
# scaffolded by default. However, you might want to replace it to use other
65
68
# tools. (i.e. podman)
66
69
CONTAINER_TOOL ?= docker
70
+ # Dockerfile was renamed to Containerfile, presumably for podman support, however
71
+ # this makefile explicitly mentions Dockerfile, so we parameterize it
72
+ CONTAINER_FILE ?= Dockerfile
67
73
68
74
# Setting SHELL to bash allows bash commands to be executed by recipes.
69
75
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -139,15 +145,44 @@ build: manifests generate fmt vet ## Build manager binary.
139
145
go build -o bin/manager cmd/main.go
140
146
141
147
.PHONY : run
142
- run : manifests generate fmt vet # # Run a controller from your host.
148
+ run : manifests generate fmt vet generate-local-certs # # Run a controller from your host.
143
149
go run ./cmd/main.go
144
150
151
+ .PHONY : generate-certs
152
+ generate-certs : # # Generate TLS certificates to specified directory (use CERT_DIR=path)
153
+ @if [ -z " $( CERT_DIR) " ]; then \
154
+ echo " Error: CERT_DIR must be specified. Usage: make generate-certs CERT_DIR=/path/to/certs" ; \
155
+ exit 1; \
156
+ fi
157
+ @echo " Generating TLS certificates in $( CERT_DIR) ..."
158
+ @if command -v cfssl & > /dev/null && [[ -f " generate-tls.sh" ]]; then \
159
+ echo " Using cfssl-based certificate generation" ; \
160
+ ./generate-tls.sh $(CERT_DIR ) ; \
161
+ elif [[ -f " generate-tls-openssl.sh" ]]; then \
162
+ echo " Using OpenSSL-based certificate generation" ; \
163
+ ./generate-tls-openssl.sh $(CERT_DIR ) ; \
164
+ else \
165
+ echo " Error: No TLS generation script found. Either install cfssl or ensure generate-tls-openssl.sh exists." ; \
166
+ exit 1; \
167
+ fi
168
+
169
+ .PHONY : generate-local-certs
170
+ generate-local-certs : # # Generate TLS certificates for local development
171
+ @echo " Generating local webhook certificates..."
172
+ @CERT_DIR=$$(mktemp -d ) && \
173
+ $(MAKE ) generate-certs CERT_DIR=$$ CERT_DIR && \
174
+ mkdir -p " $$ TMPDIR/k8s-webhook-server/serving-certs" && \
175
+ cp $$ CERT_DIR/tls.crt " $$ TMPDIR/k8s-webhook-server/serving-certs/" && \
176
+ cp $$ CERT_DIR/tls.key " $$ TMPDIR/k8s-webhook-server/serving-certs/" && \
177
+ echo " Certificates generated and placed in $$ TMPDIR/k8s-webhook-server/serving-certs/" && \
178
+ echo " You can now run 'make run' to start the controller with webhook support"
179
+
145
180
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
146
181
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
147
182
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
148
183
.PHONY : docker-build
149
- docker-build : # # Build docker image with the manager.
150
- $(CONTAINER_TOOL ) build -f Containerfile -t ${IMG } .
184
+ docker-build : test # # Build docker image with the manager.
185
+ $(CONTAINER_TOOL ) build -t ${IMG} -f ${CONTAINER_FILE } .
151
186
152
187
.PHONY : docker-push
153
188
docker-push : # # Push docker image with the manager.
@@ -163,18 +198,17 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
163
198
.PHONY : docker-buildx
164
199
docker-buildx : # # Build and push docker image for the manager for cross-platform support
165
200
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
166
- sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile .cross
201
+ sed -e ' 1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ${CONTAINER_FILE} > ${CONTAINER_FILE} .cross
167
202
- $(CONTAINER_TOOL ) buildx create --name model-validation-operator-builder
168
203
$(CONTAINER_TOOL ) buildx use model-validation-operator-builder
169
- - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f Dockerfile .cross .
204
+ - $(CONTAINER_TOOL ) buildx build --push --platform=$(PLATFORMS ) --tag ${IMG} -f ${CONTAINER_FILE} .cross .
170
205
- $(CONTAINER_TOOL ) buildx rm model-validation-operator-builder
171
- rm Dockerfile .cross
206
+ rm ${CONTAINER_FILE} .cross
172
207
173
208
.PHONY : build-installer
174
- build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
175
- mkdir -p dist
176
- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
177
- $(KUSTOMIZE ) build config/default > dist/install.yaml
209
+ build-installer : manifests # # Generate a consolidated YAML with CRDs and deployment.
210
+ ./scripts/generate-manifests.sh production dist
211
+ mv dist/production.yaml dist/install.yaml
178
212
179
213
# #@ Deployment
180
214
@@ -192,12 +226,13 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
192
226
193
227
.PHONY : deploy
194
228
deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
195
- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
196
- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
229
+ cd config/overlays/production && $(KUSTOMIZE ) edit set image controller=${IMG}
230
+ cd config/overlays/production && $(KUSTOMIZE ) edit set replicas controller-manager=1
231
+ $(KUSTOMIZE ) build config/overlays/production | $(KUBECTL ) apply -f -
197
232
198
233
.PHONY : undeploy
199
234
undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
200
- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
235
+ $(KUSTOMIZE ) build config/overlays/production | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
201
236
202
237
# #@ Dependencies
203
238
@@ -215,13 +250,12 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
215
250
GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
216
251
217
252
# # Tool Versions
218
- KUSTOMIZE_VERSION ?= v5.6.0
219
- CONTROLLER_TOOLS_VERSION ?= v0.17.2
220
- # ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
253
+ KUSTOMIZE_VERSION ?= v5.7.0
254
+ CONTROLLER_TOOLS_VERSION ?= v0.18.0
221
255
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-% d.% d", $$2, $$3}')
222
256
# ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
223
257
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.% d", $$3}')
224
- GOLANGCI_LINT_VERSION ?= v1.63.4
258
+ GOLANGCI_LINT_VERSION ?= v2.3.0
225
259
226
260
.PHONY : kustomize
227
261
kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
@@ -239,7 +273,7 @@ setup-envtest: envtest ## Download the binaries required for ENVTEST in the loca
239
273
@$(ENVTEST ) use $(ENVTEST_K8S_VERSION ) --bin-dir $(LOCALBIN ) -p path || { \
240
274
echo " Error: Failed to set up envtest binaries for version $( ENVTEST_K8S_VERSION) ." ; \
241
275
exit 1; \
242
- }
276
+ } ; echo
243
277
244
278
.PHONY : envtest
245
279
envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
@@ -249,7 +283,7 @@ $(ENVTEST): $(LOCALBIN)
249
283
.PHONY : golangci-lint
250
284
golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
251
285
$(GOLANGCI_LINT ) : $(LOCALBIN )
252
- $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
286
+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2/ cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
253
287
254
288
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
255
289
# $1 - target path with name of binary
@@ -285,42 +319,49 @@ endif
285
319
endif
286
320
287
321
.PHONY : bundle
288
- bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
322
+ bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata from $(BUNDLE_OVERLAY) overlay , then validate generated files.
289
323
$(OPERATOR_SDK ) generate kustomize manifests -q
290
- cd config/manager && $(KUSTOMIZE ) edit set image controller=$(IMG )
291
- $(KUSTOMIZE ) build config/manifests | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
324
+ cd config/overlays/$(BUNDLE_OVERLAY ) && $(KUSTOMIZE ) edit set image controller=$(IMG )
325
+ $(KUSTOMIZE ) build config/overlays/$(BUNDLE_OVERLAY ) | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
326
+ # Fix webhook configuration in CSV
327
+ @if [ -f bundle/manifests/model-validation-operator.clusterserviceversion.yaml ]; then \
328
+ sed -i.bak ' s/deploymentName: webhook/deploymentName: model-validation-controller-manager/' bundle/manifests/model-validation-operator.clusterserviceversion.yaml && \
329
+ sed -i.bak2 ' s/deploymentName: model-validation-controller-manager/deploymentName: model-validation-controller-manager\n serviceName: model-validation-webhook/' bundle/manifests/model-validation-operator.clusterserviceversion.yaml && \
330
+ rm -f bundle/manifests/model-validation-operator.clusterserviceversion.yaml.bak bundle/manifests/model-validation-operator.clusterserviceversion.yaml.bak2; \
331
+ fi
292
332
$(OPERATOR_SDK ) bundle validate ./bundle
293
333
294
334
.PHONY : bundle-build
295
335
bundle-build : # # Build the bundle image.
296
- $(CONTAINER_TOOL ) build -f bundle.Dockerfile -t $(BUNDLE_IMG ) .
336
+ $(CONTAINER_TOOL ) build -f bundle.${CONTAINER_FILE} -t $(BUNDLE_IMG ) .
297
337
298
338
.PHONY : bundle-push
299
339
bundle-push : # # Push the bundle image.
300
340
$(MAKE ) docker-push IMG=$(BUNDLE_IMG )
301
341
302
342
.PHONY : opm
303
343
OPM = $(LOCALBIN ) /opm
344
+ OPM_VERSION =v1.56.0
304
345
opm : # # Download opm locally if necessary.
305
346
ifeq (,$(wildcard $(OPM ) ) )
306
347
ifeq (,$(shell which opm 2>/dev/null) )
307
348
@{ \
308
349
set -e ;\
309
350
mkdir -p $(dir $(OPM)) ;\
310
351
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
311
- curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.55.0 /$${OS}-$${ARCH}-opm ;\
352
+ curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/${OPM_VERSION} /$${OS}-$${ARCH}-opm ;\
312
353
chmod +x $(OPM) ;\
313
354
}
314
355
else
315
356
OPM = $(shell which opm)
316
357
endif
317
358
endif
318
359
319
- # A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/ operator-bundle:v0.1.0,example.com/ operator-bundle:v0.2.0).
360
+ # A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=ghcr.io/sigstore/model-validation- operator-bundle:v0.1.0,ghcr.io/sigstore/model-validation- operator-bundle:v0.2.0).
320
361
# These images MUST exist in a registry and be pull-able.
321
362
BUNDLE_IMGS ?= $(BUNDLE_IMG )
322
363
323
- # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/ operator-catalog:v0.2.0).
364
+ # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=ghcr.io/sigstore/model-validation- operator-catalog:v0.2.0).
324
365
CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -catalog:v$(VERSION )
325
366
326
367
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
@@ -333,9 +374,48 @@ endif
333
374
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
334
375
.PHONY : catalog-build
335
376
catalog-build : opm # # Build a catalog image.
336
- $(OPM ) index add --container-tool $( CONTAINER_TOOL ) --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
377
+ $(OPM ) index add --container-tool ${ CONTAINER_TOOL} --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
337
378
338
379
# Push the catalog image.
339
380
.PHONY : catalog-push
340
381
catalog-push : # # Push a catalog image.
341
382
$(MAKE ) docker-push IMG=$(CATALOG_IMG )
383
+
384
+ # #@ Overlay Deployment
385
+
386
+ # Define available environments
387
+ ENVIRONMENTS := testing production development olm
388
+
389
+ # Generic deployment target using generate-manifests script
390
+ define deploy-environment
391
+ .PHONY: deploy-$(1 )
392
+ deploy-$(1 ) : manifests # # Deploy to $(1) environment
393
+ ./scripts/generate-manifests.sh $(1 ) manifests
394
+ kubectl apply -f manifests/$(1 ) .yaml
395
+ endef
396
+
397
+ # Generic undeployment target
398
+ define undeploy-environment
399
+ .PHONY: undeploy-$(1 )
400
+ undeploy-$(1 ) : # # Undeploy from $(1) environment
401
+ kubectl delete -f manifests/$(1 ) .yaml --ignore-not-found=true
402
+ endef
403
+
404
+ # Generate targets for all environments
405
+ $(foreach env,$(ENVIRONMENTS),$(eval $(call deploy-environment,$(env))))
406
+ $(foreach env,$(ENVIRONMENTS),$(eval $(call undeploy-environment,$(env))))
407
+
408
+ # Convenience targets for all environments
409
+ .PHONY : deploy-all
410
+ deploy-all : $(addprefix deploy-,$(ENVIRONMENTS ) ) # # Deploy to all environments (use with caution)
411
+
412
+ .PHONY : undeploy-all
413
+ undeploy-all : $(addprefix undeploy-,$(ENVIRONMENTS ) ) # # Undeploy from all environments
414
+
415
+ # Generate manifests using script (replaces removed render targets)
416
+ .PHONY : generate-manifests
417
+ generate-manifests : manifests # # Generate manifests for all environments using generate-manifests script
418
+ @for env in $(ENVIRONMENTS ) ; do \
419
+ echo " Generating manifests for $$ env environment..." ; \
420
+ ./scripts/generate-manifests.sh $$ env manifests; \
421
+ done
0 commit comments