Skip to content

Commit 2374a4b

Browse files
stuggiclaude
andcommitted
Add OLM upgrade support to Makefile
Add REPLACES variable to inject `replaces` field into the CSV for OLM upgrade paths. Add PREV_BUNDLE_IMG and CATALOG_BUNDLE_IMGS variables to support incremental and from-scratch catalog builds with full upgrade chains. Fix kustomization.yaml patch accumulation by clearing old patches before regenerating. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent 3fd1765 commit 2374a4b

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

Makefile

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
4848
BUNDLE_GEN_FLAGS += --use-image-digests
4949
endif
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.
5357
OPERATOR_SDK_VERSION ?= v1.41.1
@@ -398,10 +402,16 @@ endif
398402
.PHONY: bundle
399403
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
400404
$(OPERATOR_SDK) generate kustomize manifests -q
401-
cd config/operator/deployment/ && $(KUSTOMIZE) edit set image controller=$(IMG) && \
405+
cd config/operator/deployment/ && \
406+
sed -i '/^patches:/,$$d' kustomization.yaml && \
407+
$(KUSTOMIZE) edit set image controller=$(IMG) && \
402408
$(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)\"}}]" && \
403409
$(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)\"}}]"
404410
$(KUSTOMIZE) build config/operator --load-restrictor='LoadRestrictionsNone' | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
411+
ifneq ($(REPLACES),)
412+
@echo "Adding replaces: $(REPLACES) to CSV"
413+
sed -i "/^ name: openstack-operator.v$(VERSION)/a\ replaces: $(REPLACES)" bundle/manifests/openstack-operator.clusterserviceversion.yaml
414+
endif
405415
$(OPERATOR_SDK) bundle validate ./bundle
406416

407417
.PHONY: bundle-build
@@ -448,12 +458,30 @@ SHELL_EXPORT = $(foreach v,$(MAKE_ENV),$(v)='$($(v))')
448458
# These images MUST exist in a registry and be pull-able.
449459
BUNDLE_IMGS = "$(BUNDLE_IMG)$(shell $(SHELL_EXPORT) /bin/bash hack/pin-bundle-images.sh || echo bundle-fail-tag)"
450460

461+
# When REPLACES is set, include the previous version's bundle in the catalog for upgrade support
462+
# PREV_BUNDLE_IMG can be set to override the default (defaults to upstream :latest)
463+
# Example: make catalog-build REPLACES=openstack-operator.v0.6.0 PREV_BUNDLE_IMG=quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
464+
ifneq ($(REPLACES),)
465+
PREV_BUNDLE_IMG ?= quay.io/openstack-k8s-operators/openstack-operator-bundle:latest
466+
endif
467+
451468
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
452469
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-index:v$(VERSION)
453470

454471
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
472+
# When using a base catalog, only add the NEW bundle (base already has everything else)
473+
# Alternatively, set CATALOG_BUNDLE_IMGS directly to specify all bundles (for building from scratch without a base)
455474
ifneq ($(origin CATALOG_BASE_IMG), undefined)
456475
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
476+
CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMG)
477+
else
478+
# Building from scratch: include previous bundle if REPLACES is set, plus all dependency bundles
479+
# Can be overridden by setting CATALOG_BUNDLE_IMGS on command line
480+
ifneq ($(REPLACES),)
481+
CATALOG_BUNDLE_IMGS ?= $(PREV_BUNDLE_IMG),$(BUNDLE_IMGS)
482+
else
483+
CATALOG_BUNDLE_IMGS ?= $(BUNDLE_IMGS)
484+
endif
457485
endif
458486

459487
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
@@ -462,7 +490,7 @@ endif
462490
.PHONY: catalog-build
463491
catalog-build: opm ## Build a catalog image.
464492
# FIXME: hardcoded bundle below should use go.mod pinned version for manila bundle
465-
$(OPM) index add --container-tool podman --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
493+
$(OPM) index add --container-tool podman --mode semver --tag $(CATALOG_IMG) --bundles $(CATALOG_BUNDLE_IMGS) $(FROM_INDEX_OPT)
466494

467495
# Push the catalog image.
468496
.PHONY: catalog-push

0 commit comments

Comments
 (0)