Skip to content

Commit b8d882a

Browse files
Merge pull request #1873 from stuggi/olm_update
Add OLM upgrade support to Makefile
2 parents 36789c2 + 037d265 commit b8d882a

2 files changed

Lines changed: 50 additions & 49 deletions

File tree

Makefile

Lines changed: 33 additions & 3 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
@@ -397,10 +401,16 @@ endif
397401
.PHONY: bundle
398402
bundle: 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
445455
SHELL_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.
448460
BUNDLE_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).
451470
CATALOG_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).
454475
ifneq ($(origin CATALOG_BASE_IMG), undefined)
455476
FROM_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
456486
endif
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
462492
catalog-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

hack/pin-bundle-images.sh

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -43,62 +43,33 @@ for MOD_PATH in ${MOD_PATHS}; do
4343
CURL_REGISTRY="quay.io"
4444
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/openstack-k8s-operators"
4545
REPO_URL="${CURL_REGISTRY}/openstack-k8s-operators"
46-
47-
# IMAGEBASE takes precedence - if this operator matches IMAGEBASE, use custom registry
48-
if [[ "$BASE" == "$IMAGEBASE" ]]; then
49-
REPO_URL="${IMAGEREGISTRY}/${IMAGENAMESPACE}"
50-
CURL_REGISTRY="${IMAGEREGISTRY}"
51-
if [[ ${LOCAL_REGISTRY} -eq 1 ]]; then
52-
REPO_CURL_URL="http://${CURL_REGISTRY}/v2/${IMAGENAMESPACE}"
53-
elif [[ "${CURL_REGISTRY}" == "docker.io" ]]; then
54-
REPO_CURL_URL="https://hub.docker.com/v2/repositories/${IMAGENAMESPACE}"
55-
else
56-
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/${IMAGENAMESPACE}"
57-
fi
58-
# For operators with replace directives (non-openstack-k8s-operators users),
59-
# bundle images are only on quay.io, not mirrored to local registry
60-
elif [[ "$GITHUB_USER" != "openstack-k8s-operators" ]]; then
61-
# Force quay.io for replaced operators, use the GitHub user's namespace
62-
CURL_REGISTRY="quay.io"
63-
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/${GITHUB_USER}"
64-
REPO_URL="${CURL_REGISTRY}/${GITHUB_USER}"
65-
# For standard operators with custom registry settings
66-
elif [[ "$IMAGENAMESPACE" != "openstack-k8s-operators" || "${IMAGEREGISTRY}" != "quay.io" ]]; then
67-
REPO_URL="${IMAGEREGISTRY}/${IMAGENAMESPACE}"
68-
CURL_REGISTRY="${IMAGEREGISTRY}"
69-
# Quay registry v2 api does not return all the tags that's why keeping v1 for quay and v2
70-
# for local registry
71-
if [[ ${LOCAL_REGISTRY} -eq 1 ]]; then
72-
REPO_CURL_URL="http://${CURL_REGISTRY}/v2/${IMAGENAMESPACE}"
73-
elif [[ "${CURL_REGISTRY}" == "docker.io" ]]; then
74-
# replace docker.io by hub.docker.com to read tags
75-
REPO_CURL_URL="https://hub.docker.com/v2/repositories/${IMAGENAMESPACE}"
46+
if [[ "$GITHUB_USER" != "openstack-k8s-operators" || "$BASE" == "$IMAGEBASE" ]]; then
47+
if [[ "$IMAGENAMESPACE" != "openstack-k8s-operators" || "${IMAGEREGISTRY}" != "quay.io" ]]; then
48+
REPO_URL="${IMAGEREGISTRY}/${IMAGENAMESPACE}"
49+
CURL_REGISTRY="${IMAGEREGISTRY}"
50+
# Quay registry v2 api does not return all the tags that's why keeping v1 for quay and v2
51+
# for local registry
52+
if [[ ${LOCAL_REGISTRY} -eq 1 ]]; then
53+
REPO_CURL_URL="http://${CURL_REGISTRY}/v2/${IMAGENAMESPACE}"
54+
elif [[ "${CURL_REGISTRY}" == "docker.io" ]]; then
55+
# replace docker.io by hub.docker.com to read tags
56+
REPO_CURL_URL="https://hub.docker.com/v2/repositories/${IMAGENAMESPACE}"
57+
else
58+
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/${IMAGENAMESPACE}"
59+
fi
7660
else
77-
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/${IMAGENAMESPACE}"
61+
REPO_CURL_URL="https://${CURL_REGISTRY}/api/v1/repository/${GITHUB_USER}"
62+
REPO_URL="${CURL_REGISTRY}/${GITHUB_USER}"
7863
fi
7964
fi
8065

81-
# Query local registry only for standard operators (openstack-k8s-operators) or custom IMAGEBASE
82-
# Replaced operators (e.g., lmiccini/*) always query quay.io since bundles aren't mirrored locally
83-
if [[ ${LOCAL_REGISTRY} -eq 1 && ( "$GITHUB_USER" == "openstack-k8s-operators" || "$BASE" == "$IMAGEBASE" ) ]]; then
66+
if [[ ${LOCAL_REGISTRY} -eq 1 && ( "$GITHUB_USER" != "openstack-k8s-operators" || "$BASE" == "$IMAGEBASE" ) ]]; then
8467
SHA=$(curl -s ${REPO_CURL_URL}/$BASE-operator-bundle/tags/list | jq -r '.tags // [] | .[]' | sort -u | { grep $REF || true; })
85-
# If local registry doesn't have the bundle, fall back to quay.io
86-
if [ -z "$SHA" ]; then
87-
SHA=$(curl -s https://quay.io/api/v1/repository/openstack-k8s-operators/$BASE-operator-bundle/tag/?onlyActiveTags=true\&filter_tag_name=like:$REF | jq -r '.tags // [] | .[].name')
88-
# Update REPO_URL to use quay.io since we're falling back
89-
REPO_URL="quay.io/openstack-k8s-operators"
90-
fi
9168
elif [[ "${CURL_REGISTRY}" == "docker.io" ]]; then
9269
SHA=$(curl -s ${REPO_CURL_URL}/$BASE-operator-bundle/tags/?page_size=100 | jq -r '.results // [] | .[].name' | sort -u | { grep $REF || true; })
9370
elif [[ "${CURL_REGISTRY}" != "quay.io" ]]; then
9471
# quay.rdoproject.io doesn't support filter_tag_name, so increase limit to 100
9572
SHA=$(curl -s ${REPO_CURL_URL}/$BASE-operator-bundle/tag/?onlyActiveTags=true\&limit=100 | jq -r '.tags // [] | .[].name' | sort -u | { grep $REF || true; })
96-
# If non-quay.io registry doesn't have the bundle for openstack-k8s-operators, fall back to quay.io
97-
if [[ -z "$SHA" && "$GITHUB_USER" == "openstack-k8s-operators" ]]; then
98-
SHA=$(curl -s https://quay.io/api/v1/repository/openstack-k8s-operators/$BASE-operator-bundle/tag/?onlyActiveTags=true\&filter_tag_name=like:$REF | jq -r '.tags // [] | .[].name')
99-
# Update REPO_URL to use quay.io since we're falling back
100-
REPO_URL="quay.io/openstack-k8s-operators"
101-
fi
10273
else
10374
SHA=$(curl -s ${REPO_CURL_URL}/$BASE-operator-bundle/tag/?onlyActiveTags=true\&filter_tag_name=like:$REF | jq -r '.tags // [] | .[].name')
10475
fi

0 commit comments

Comments
 (0)