@@ -48,6 +48,10 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
4848 BUNDLE_GEN_FLAGS += --use-image-digests
4949endif
5050
51+ # REPLACES is the previous version that this version replaces (for OLM upgrades)
52+ # Example: make bundle REPLACES=openstack-operator.v0.6.0 VERSION=0.6.1
53+ REPLACES ?=
54+
5155# Set the Operator SDK version to use. By default, what is installed on the system is used.
5256# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
5357OPERATOR_SDK_VERSION ?= v1.41.1
@@ -397,10 +401,16 @@ endif
397401.PHONY : bundle
398402bundle : manifests kustomize operator-sdk # # Generate bundle manifests and metadata, then validate generated files.
399403 $(OPERATOR_SDK ) generate kustomize manifests -q
400- cd config/operator/deployment/ && $(KUSTOMIZE ) edit set image controller=$(IMG ) && \
404+ cd config/operator/deployment/ && \
405+ sed -i ' /^patches:/,$$d' kustomization.yaml && \
406+ $(KUSTOMIZE ) edit set image controller=$(IMG ) && \
401407 $(KUSTOMIZE ) edit add patch --kind Deployment --name openstack-operator-controller-init --namespace system --patch " [{\" op\" : \" replace\" , \" path\" : \" /spec/template/spec/containers/0/env/0\" , \" value\" : {\" name\" : \" OPENSTACK_RELEASE_VERSION\" , \" value\" : \" $( OPENSTACK_RELEASE_VERSION) \" }}]" && \
402408 $(KUSTOMIZE ) edit add patch --kind Deployment --name openstack-operator-controller-init --namespace system --patch " [{\" op\" : \" replace\" , \" path\" : \" /spec/template/spec/containers/0/env/1\" , \" value\" : {\" name\" : \" OPERATOR_IMAGE_URL\" , \" value\" : \" $( IMG) \" }}]"
403409 $(KUSTOMIZE ) build config/operator --load-restrictor=' LoadRestrictionsNone' | $(OPERATOR_SDK ) generate bundle $(BUNDLE_GEN_FLAGS )
410+ ifneq ($(REPLACES ) ,)
411+ @echo "Adding replaces: $(REPLACES) to CSV"
412+ sed -i "/^ name: openstack-operator.v$(VERSION)/a\ replaces: $(REPLACES)" bundle/manifests/openstack-operator.clusterserviceversion.yaml
413+ endif
404414 $(OPERATOR_SDK) bundle validate ./bundle
405415
406416.PHONY : bundle-build
@@ -447,12 +457,30 @@ SHELL_EXPORT = $(foreach v,$(MAKE_ENV),$(v)='$($(v))')
447457# These images MUST exist in a registry and be pull-able.
448458BUNDLE_IMGS = "$(BUNDLE_IMG )$(shell $(SHELL_EXPORT ) /bin/bash hack/pin-bundle-images.sh || echo bundle-fail-tag) "
449459
460+ # When REPLACES is set, include the previous version's bundle in the catalog for upgrade support
461+ # PREV_BUNDLE_IMG can be set to override the default (defaults to upstream :latest)
462+ # Example: make catalog-build REPLACES=openstack-operator.v0.6.0 PREV_BUNDLE_IMG=quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
463+ ifneq ($(REPLACES ) ,)
464+ PREV_BUNDLE_IMG ?= quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
465+ endif
466+
450467# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
451468CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -index:v$(VERSION )
452469
453470# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
471+ # When using a base catalog, only add the NEW bundle (base already has everything else)
472+ # Alternatively, set CATALOG_BUNDLE_IMGS directly to specify all bundles (for building from scratch without a base)
454473ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
455474FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
475+ CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMG )
476+ else
477+ # Building from scratch: include previous bundle if REPLACES is set, plus all dependency bundles
478+ # Can be overridden by setting CATALOG_BUNDLE_IMGS on command line
479+ ifneq ($(REPLACES ) ,)
480+ CATALOG_BUNDLE_IMGS ?= $(PREV_BUNDLE_IMG ) ,$(BUNDLE_IMGS )
481+ else
482+ CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMGS )
483+ endif
456484endif
457485
458486# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
@@ -461,7 +489,7 @@ endif
461489.PHONY : catalog-build
462490catalog-build : opm # # Build a catalog image.
463491 # FIXME: hardcoded bundle below should use go.mod pinned version for manila bundle
464- $(OPM ) index add --container-tool podman --mode semver --tag $(CATALOG_IMG ) --bundles $(BUNDLE_IMGS ) $(FROM_INDEX_OPT )
492+ $(OPM ) index add --container-tool podman --mode semver --tag $(CATALOG_IMG ) --bundles $(CATALOG_BUNDLE_IMGS ) $(FROM_INDEX_OPT )
465493
466494# Push the catalog image.
467495.PHONY : catalog-push
0 commit comments