Skip to content

Commit 894f786

Browse files
author
Shai Levi
committed
build file based catalog
1 parent 16052be commit 894f786

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

Makefile

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ YQ_VERSION = v4.44.1
4242
OPERATOR_NAME ?= self-node-remediation
4343
OPERATOR_NAMESPACE ?= openshift-workload-availability
4444

45+
BLUE_ICON_PATH = "./config/assets/snr_icon_blue.png"
46+
4547
# VERSION defines the project version for the bundle.
4648
# Update this value when you upgrade the version of your project.
4749
# To re-generate a bundle for another specific version without changing the standard setup, you can:
@@ -313,7 +315,7 @@ rm -rf $$TMP_DIR ;\
313315
}
314316
endef
315317

316-
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ./config/assets/snr_icon_blue.png)
318+
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ${BLUE_ICON_PATH})
317319
export ICON_BASE64 ?= ${DEFAULT_ICON_BASE64}
318320
export CSV ?= "./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"
319321
.PHONY: bundle
@@ -455,15 +457,43 @@ ifeq (,$(wildcard $(OPM)))
455457
endif
456458

457459
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMG to that image.
458-
ifneq ($(origin CATALOG_BASE_IMG), undefined)
459-
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
460-
endif
460+
# Build a file-based catalog image
461+
# https://docs.openshift.com/container-platform/4.14/operators/admin/olm-managing-custom-catalogs.html#olm-managing-custom-catalogs-fb
462+
# NOTE: CATALOG_DIR and CATALOG_DOCKERFILE items won't be deleted in case of recipe's failure
463+
CATALOG_DIR := catalog
464+
CATALOG_DOCKERFILE := ${CATALOG_DIR}.Dockerfile
465+
CATALOG_INDEX := $(CATALOG_DIR)/index.yaml
466+
467+
.PHONY: add_channel_entry_for_the_bundle
468+
add_channel_entry_for_the_bundle:
469+
@echo "---" >> ${CATALOG_INDEX}
470+
@echo "schema: olm.channel" >> ${CATALOG_INDEX}
471+
@echo "package: ${OPERATOR_NAME}" >> ${CATALOG_INDEX}
472+
@echo "name: ${CHANNELS}" >> ${CATALOG_INDEX}
473+
@echo "entries:" >> ${CATALOG_INDEX}
474+
@echo " - name: ${OPERATOR_NAME}.v${VERSION}" >> ${CATALOG_INDEX}
475+
461476
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
462477
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
463478
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
464479
.PHONY: catalog-build
465-
catalog-build: opm ## Build a catalog image.
466-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMG) $(FROM_INDEX_OPT)
480+
catalog-build: opm ## Build a file-based catalog image.
481+
# Remove the catalog directory and Dockerfile
482+
-rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}
483+
@mkdir -p ${CATALOG_DIR}
484+
$(OPM) generate dockerfile ${CATALOG_DIR}
485+
$(OPM) init ${OPERATOR_NAME} \
486+
--default-channel=${CHANNELS} \
487+
--description=./README.md \
488+
--icon=${BLUE_ICON_PATH} \
489+
--output yaml \
490+
> ${CATALOG_INDEX}
491+
$(OPM) render ${BUNDLE_IMG} --output yaml >> ${CATALOG_INDEX}
492+
$(MAKE) add_channel_entry_for_the_bundle
493+
$(OPM) validate ${CATALOG_DIR}
494+
docker build . -f ${CATALOG_DOCKERFILE} -t ${CATALOG_IMG}
495+
# Clean up the catalog directory and Dockerfile
496+
rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}
467497

468498
.PHONY: catalog-push
469499
catalog-push: ## Push a catalog image.

0 commit comments

Comments
 (0)