Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.18] Build a file-based catalog #145

Open
wants to merge 2 commits into
base: release-0.18
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ OCP_VERSION ?= 4.14
YQ_API_VERSION = v4
YQ_VERSION = v4.42.1

BLUE_ICON_PATH = "./config/assets/nmo_blue_icon.png"

# IMAGE_REGISTRY used to indicate the registery/group for the operator, bundle and catalog
IMAGE_REGISTRY ?= quay.io/medik8s
export IMAGE_REGISTRY
Expand Down Expand Up @@ -202,7 +204,7 @@ bundle-run: operator-sdk ## Run bundle image. Default NS is "openshift-workload-
$(OPERATOR_SDK) -n $(OPERATOR_NAMESPACE) run bundle $(BUNDLE_IMG)

.PHONY: bundle-run-update
bundle-run-update: operator-sdk ## Update bundle image.
bundle-run-update: operator-sdk ## Update bundle image.
# An older bundle image CSV should exist in the cluster, and in the same namespace,
# Default NS is "openshift-workload-availability", redefine OPERATOR_NAMESPACE to override it.
$(OPERATOR_SDK) -n $(OPERATOR_NAMESPACE) run bundle-upgrade $(BUNDLE_IMG)
Expand All @@ -213,7 +215,7 @@ bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run

##@ Bundle Creation Addition
## Some addition to bundle creation in the bundle
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ./config/assets/nmo_blue_icon.png)
DEFAULT_ICON_BASE64 := $(shell base64 --wrap=0 ${BLUE_ICON_PATH})
export ICON_BASE64 ?= ${DEFAULT_ICON_BASE64}
export CSV ?= "./bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml"

Expand Down Expand Up @@ -347,7 +349,7 @@ kustomize: ## Download kustomize locally if necessary.
$(call go-install-tool,$(KUSTOMIZE),$(KUSTOMIZE_DIR),sigs.k8s.io/kustomize/kustomize/$(KUSTOMIZE_VERSION))

.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),$(CONTROLLER_GEN_DIR),sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION})

.PHONY: envtest
Expand Down Expand Up @@ -397,7 +399,7 @@ bundle: manifests operator-sdk kustomize ## Generate bundle manifests and metada
bundle-k8s: bundle # Generate bundle manifests and metadata for Kubernetes, then validate generated files.
$(KUSTOMIZE) build config/manifests-k8s | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(MAKE) bundle-validate

.PHONY: bundle-validate
bundle-validate: operator-sdk ## Validate the bundle directory with additional validators (suite=operatorframework), such as Kubernetes deprecated APIs (https://kubernetes.io/docs/reference/using-api/deprecation-guide/) based on bundle.CSV.Spec.MinKubeVersion
$(OPERATOR_SDK) bundle validate ./bundle --select-optional suite=operatorframework
Expand Down Expand Up @@ -430,9 +432,21 @@ define url-install-tool
}
endef

ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif
# Build a file-based catalog image
# https://docs.openshift.com/container-platform/4.14/operators/admin/olm-managing-custom-catalogs.html#olm-managing-custom-catalogs-fb
# NOTE: CATALOG_DIR and CATALOG_DOCKERFILE items won't be deleted in case of recipe's failure
CATALOG_DIR := catalog
CATALOG_DOCKERFILE := ${CATALOG_DIR}.Dockerfile
CATALOG_INDEX := $(CATALOG_DIR)/index.yaml

.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}

.PHONY: build-tools
build-tools: ## Download & build all the tools locally if necessary.
Expand All @@ -442,8 +456,23 @@ build-tools: ## Download & build all the tools locally if necessary.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMG) $(FROM_INDEX_OPT)
catalog-build: opm ## Build a file-based catalog image.
# Remove the catalog directory and Dockerfile
-rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}
@mkdir -p ${CATALOG_DIR}
$(OPM) generate dockerfile ${CATALOG_DIR}
$(OPM) init ${OPERATOR_NAME} \
--default-channel=${CHANNELS} \
--description=./README.md \
--icon=${BLUE_ICON_PATH} \
--output yaml \
> ${CATALOG_INDEX}
$(OPM) render ${BUNDLE_IMG} --output yaml >> ${CATALOG_INDEX}
$(MAKE) add_channel_entry_for_the_bundle
$(OPM) validate ${CATALOG_DIR}
docker build . -f ${CATALOG_DOCKERFILE} -t ${CATALOG_IMG}
# Clean up the catalog directory and Dockerfile
rm -r ${CATALOG_DIR} ${CATALOG_DOCKERFILE}

.PHONY: catalog-push
catalog-push: ## Push a catalog image.
Expand All @@ -453,17 +482,17 @@ catalog-push: ## Push a catalog image.

.PHONY: test-scorecard
test-scorecard: operator-sdk ## Run Scorecard testing for the bundle directory on OPERATOR_NAMESPACE
$(OPERATOR_SDK) scorecard ./bundle -n $(OPERATOR_NAMESPACE)
$(OPERATOR_SDK) scorecard ./bundle -n $(OPERATOR_NAMESPACE)

.PHONY: check
.PHONY: check
check: ## Dockerized version of make test
$(DOCKER_GO) "make test"

.PHONY: verify-unchanged
verify-unchanged: ## Verify there are no un-committed changes
./hack/verify-unchanged.sh

.PHONY: container-build
.PHONY: container-build
container-build: check ## Build containers
$(DOCKER_GO) "make bundle"
make docker-build bundle-build
Expand All @@ -475,12 +504,12 @@ bundle-build-community: bundle-community ## Run bundle community changes in CSV,
.PHONY: container-build-community
container-build-community: docker-build bundle-build-community ## Build containers for community

.PHONY: container-push
.PHONY: container-push
container-push: docker-push bundle-push catalog-build catalog-push## Push containers (NOTE: catalog can't be build before bundle was pushed)

.PHONY: container-build-and-push-community
container-build-and-push-community: container-build-community container-push ## Build four images, update CSV for community, and push all the images to Quay (docker, bundle, and catalog).

.PHONY: cluster-functest
.PHONY: cluster-functest
cluster-functest: ginkgo ## Run e2e tests in a real cluster
./hack/functest.sh $(GINKGO_VERSION)