Skip to content

Commit 1b89629

Browse files
committed
Build a file-based catalog
Replace the deprecated db-based catalog with a file-based one. Signed-off-by: Carlo Lobrano <[email protected]>
1 parent 00d9b4c commit 1b89629

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

Diff for: Makefile

+41-13
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ OPERATOR_NAMESPACE ?= openshift-workload-availability
9595
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
9696
BUNDLE_IMG ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME)-bundle:$(IMAGE_TAG)
9797

98-
# INDEX_IMG defines the image:tag used for the index.
99-
# You can use it as an arg. (E.g make bundle-build INDEX_IMG=<some-registry>/<project-name-index>:<tag>)
100-
INDEX_IMG ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME)-index:$(IMAGE_TAG)
98+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
99+
# NOTE: keeping the `-index` appendix to keep the same name already used for the catalog.
100+
CATALOG_IMG ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME)-index:$(IMAGE_TAG)
101101

102102
# Image URL to use all building/pushing image targets
103103
IMG ?= $(IMAGE_REGISTRY)/$(OPERATOR_NAME):$(IMAGE_TAG)
@@ -459,17 +459,45 @@ bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run
459459
create-ns: ## Create namespace
460460
$(KUBECTL) get ns $(OPERATOR_NAMESPACE) 2>&1> /dev/null || $(KUBECTL) create ns $(OPERATOR_NAMESPACE)
461461

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

469497
# Push the catalog image.
470-
.PHONY: index-push
471-
index-push: ## Push a catalog image.
472-
podman push $(INDEX_IMG)
498+
.PHONY: catalog-push
499+
catalog-push: ## Push a catalog image.
500+
$(MAKE) docker-push IMG=$(CATALOG_IMG)
473501

474502
.PHONY: test-e2e
475503
test-e2e: ## Run end to end tests
@@ -502,7 +530,7 @@ container-build-metrics: ## Build containers for K8s with metric related configu
502530

503531
.PHONY: container-push
504532
container-push: ## Push containers (NOTE: catalog can't be build before bundle was pushed)
505-
make docker-push bundle-push index-build index-push
533+
make docker-push bundle-push catalog-build catalog-push
506534

507535
.PHONY: build-and-run
508536
build-and-run: container-build container-push bundle-run

0 commit comments

Comments
 (0)