diff --git a/.gitignore b/.gitignore index 2224e01c..696b38e0 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,6 @@ tags .vscode/* .history # End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode + +catalog/ +catalog.Dockerfile diff --git a/Makefile b/Makefile index 658cff22..e56aed68 100755 --- a/Makefile +++ b/Makefile @@ -42,11 +42,22 @@ IMAGE_TAG = v$(VERSION) endif export IMAGE_TAG -CHANNELS = stable +CHANNELS ?= stable export CHANNELS -DEFAULT_CHANNEL = stable +DEFAULT_CHANNEL ?= stable export DEFAULT_CHANNEL +# Validate DEFAULT_CHANNEL is in CHANNELS +# When CHANNELS contains comma-separated values (e.g., "stable,beta"), we need to convert +# commas to spaces for filter to match. We use a variable for the comma because Make treats +# commas as function argument delimiters, causing $(subst ,, ,$(CHANNELS)) to misparse. +comma := , +ifneq (,$(DEFAULT_CHANNEL)) + ifeq (,$(filter $(DEFAULT_CHANNEL),$(subst $(comma), ,$(CHANNELS)))) + $(error DEFAULT_CHANNEL "$(DEFAULT_CHANNEL)" must be present in CHANNELS "$(CHANNELS)") + endif +endif + # VERSION defines the project version for the bundle. # Update this value when you upgrade the version of your project. # To re-generate a bundle for another specific version without changing the standard setup, you can: @@ -55,6 +66,7 @@ export DEFAULT_CHANNEL CI_VERSION := 9.9.9-dummy VERSION ?= $(DEFAULT_VERSION) PREVIOUS_VERSION ?= $(DEFAULT_VERSION) +SKIP_RANGE_LOWER ?= export VERSION # CHANNELS define the bundle channels used in the bundle. @@ -423,14 +435,29 @@ CATALOG_DIR := catalog CATALOG_DOCKERFILE := ${CATALOG_DIR}.Dockerfile CATALOG_INDEX := $(CATALOG_DIR)/index.yaml +# Add olm.channel entries for each channel in CHANNELS. +# For development version (0.0.1), omit replaces and skipRange to avoid OLM catalog validation errors. .PHONY: add_channel_entry_for_the_bundle add_channel_entry_for_the_bundle: - @echo "---" >> ${CATALOG_INDEX} - @echo "schema: olm.channel" >> ${CATALOG_INDEX} - @echo "package: ${OPERATOR_NAME}" >> ${CATALOG_INDEX} - @echo "name: ${CHANNELS}" >> ${CATALOG_INDEX} - @echo "entries:" >> ${CATALOG_INDEX} - @echo " - name: ${OPERATOR_NAME}.v${VERSION}" >> ${CATALOG_INDEX} + @for channel in $(shell echo ${CHANNELS} | tr ',' ' '); do \ + echo "---" >> ${CATALOG_INDEX}; \ + echo "schema: olm.channel" >> ${CATALOG_INDEX}; \ + echo "package: ${OPERATOR_NAME}" >> ${CATALOG_INDEX}; \ + echo "name: $$channel" >> ${CATALOG_INDEX}; \ + echo "entries:" >> ${CATALOG_INDEX}; \ + echo " - name: ${OPERATOR_NAME}.v${VERSION}" >> ${CATALOG_INDEX}; \ + \ + if [ -n "${PREVIOUS_VERSION}" ] && [ "${VERSION}" != "${DEFAULT_VERSION}" ] && [ "${PREVIOUS_VERSION}" != "${DEFAULT_VERSION}" ]; then \ + echo " replaces: ${OPERATOR_NAME}.v${PREVIOUS_VERSION}" >> ${CATALOG_INDEX}; \ + fi; \ + if [ -n "${SKIP_RANGE_LOWER}" ] && [ "${VERSION}" != "${DEFAULT_VERSION}" ] && [ "${VERSION}" != "${SKIP_RANGE_LOWER}" ]; then \ + if ! printf '%s\n' "${SKIP_RANGE_LOWER}" "${VERSION}" | sort -V -C 2>/dev/null; then \ + echo "Error: VERSION (${VERSION}) must be greater than SKIP_RANGE_LOWER (${SKIP_RANGE_LOWER})"; \ + exit 1; \ + fi; \ + echo " skipRange: '>=${SKIP_RANGE_LOWER} <${VERSION}'" >> ${CATALOG_INDEX}; \ + fi; \ + done .PHONY: build-tools build-tools: ## Download & build all the tools locally if necessary. @@ -446,7 +473,7 @@ catalog-build: opm ## Build a file-based catalog image. @mkdir -p ${CATALOG_DIR} $(OPM) generate dockerfile ${CATALOG_DIR} $(OPM) init ${OPERATOR_NAME} \ - --default-channel=${CHANNELS} \ + --default-channel=${DEFAULT_CHANNEL} \ --description=./README.md \ --icon=${BLUE_ICON_PATH} \ --output yaml \