@@ -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
@@ -445,14 +455,34 @@ MAKE_ENV := $(shell echo '$(.VARIABLES)' | awk -v RS=' ' '/^(IMAGE)|.*?(REGISTRY
445455SHELL_EXPORT = $(foreach v,$(MAKE_ENV ) ,$(v ) ='$($(v ) ) ')
446456
447457# These images MUST exist in a registry and be pull-able.
458+ # Sub-operator bundles are included for from-scratch catalog builds but are not functionally
459+ # required — sub-operators are deployed by operator-controller-init, not OLM.
448460BUNDLE_IMGS = "$(BUNDLE_IMG )$(shell $(SHELL_EXPORT ) /bin/bash hack/pin-bundle-images.sh || echo bundle-fail-tag) "
449461
462+ # When REPLACES is set, include the previous version's bundle in the catalog for upgrade support
463+ # PREV_BUNDLE_IMG can be set to override the default (defaults to upstream :latest)
464+ # Example: make catalog-build REPLACES=openstack-operator.v0.6.0 PREV_BUNDLE_IMG=quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
465+ ifneq ($(REPLACES ) ,)
466+ PREV_BUNDLE_IMG ?= quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
467+ endif
468+
450469# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
451470CATALOG_IMG ?= $(IMAGE_TAG_BASE ) -index:v$(VERSION )
452471
453- # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
472+ # Set CATALOG_BASE_IMG to an existing catalog image tag to add the new bundle to it.
473+ # Only adds the openstack-operator bundle — sub-operator bundles from the base catalog
474+ # are preserved but not functionally used (sub-operators are deployed by operator-controller-init).
454475ifneq ($(origin CATALOG_BASE_IMG ) , undefined)
455476FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG )
477+ CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMG )
478+ else
479+ # Building from scratch: include previous bundle if REPLACES is set, plus all dependency bundles
480+ # Can be overridden by setting CATALOG_BUNDLE_IMGS on command line
481+ ifneq ($(REPLACES ) ,)
482+ CATALOG_BUNDLE_IMGS ?= $(PREV_BUNDLE_IMG ) ,$(BUNDLE_IMGS )
483+ else
484+ CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMGS )
485+ endif
456486endif
457487
458488# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
@@ -461,7 +491,7 @@ endif
461491.PHONY : catalog-build
462492catalog-build : opm # # Build a catalog image.
463493 # 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 )
494+ $(OPM ) index add --container-tool podman --mode semver --tag $(CATALOG_IMG ) --bundles $(CATALOG_BUNDLE_IMGS ) $(FROM_INDEX_OPT )
465495
466496# Push the catalog image.
467497.PHONY : catalog-push
0 commit comments