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

File based catalog #201

Merged
merged 10 commits into from
Aug 28, 2024
20 changes: 10 additions & 10 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Run make catalog-generate (main)
if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }}
run: make catalog-generate REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ github.sha }}
- name: Run make catalog-generate (release)
if: ${{ github.ref_name != env.MAIN_BRANCH_NAME }}
run: make catalog-generate REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} IMAGE_TAG=${{ env.TAG_NAME }}
- name: Run make catalog
run: |
make catalog \
REGISTRY=${{ env.IMG_REGISTRY_HOST }} ORG=${{ env.IMG_REGISTRY_ORG }} \
VERSION=${{ env.VERSION }} \
AUTHORINO_VERSION=${{ github.event.inputs.authorinoVersion }} \
CHANNELS=${{ inputs.channels }}
- name: Git diff
run: git diff
- name: Build Image
Expand All @@ -208,10 +209,9 @@ jobs:
image: ${{ env.OPERATOR_NAME }}-catalog
tags: ${{ env.IMG_TAGS }}
platforms: linux/amd64,linux/arm64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR, but I do not think that catalog image needs to be multi-platform. It's just a single yaml file!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could pulling the image from a different platform fail if only amd64 is available (despite being just a single yaml inside)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image is being pulled by OLM. So, not being entirely sure, this needs to be checked first 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From OS docs:

Set --filter-by-os to the operating system and architecture to use for the base image, which must match the target OpenShift Container Platform cluster. Valid values are linux/amd64, linux/ppc64le, and linux/s390x.

Which not sure if it could be interpreted to also the actual catalog yaml img that it's delivered

build-args: |
version=${{ env.VERSION }}
containerfiles: |
./index.Dockerfile
context: ./catalog
dockerfiles: |
./catalog/${{ env.OPERATOR_NAME }}-catalog.Dockerfile
- name: Push Image
if: ${{ !env.ACT }}
id: push-to-quay
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ vendor

# Bundles
tmp

# Catalogs
/catalog/authorino-operator-catalog
/catalog/authorino-operator-catalog.Dockerfile
52 changes: 16 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Use bash as shell
SHELL = /bin/bash

MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))

# VERSION defines the project version for the bundle.
VERSION ?= $(shell git rev-parse HEAD)

Expand Down Expand Up @@ -107,10 +109,14 @@ CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.15.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
KUSTOMIZE = $(PROJECT_DIR)/bin/kustomize
$(KUSTOMIZE):
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.


YQ = $(shell pwd)/bin/yq
YQ_VERSION := v4.34.2
$(YQ):
Expand All @@ -119,22 +125,20 @@ $(YQ):
.PHONY: yq
yq: $(YQ) ## Download yq locally if necessary.

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
OPM = $(PROJECT_DIR)/bin/opm
OPM_VERSION = v1.26.2
$(OPM):
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.20.0/$${OS}-$${ARCH}-opm ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/$(OPM_VERSION)/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif

.PHONY: opm
opm: $(OPM) ## Download opm locally if necessary.


HELM = ./bin/helm
HELM_VERSION = v3.15.0
Expand Down Expand Up @@ -322,30 +326,6 @@ prepare-release:
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(IMAGE_TAG)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# 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_IMGS) $(FROM_INDEX_OPT)

.PHONY: catalog-generate
catalog-generate: opm ## Generate a catalog/index Dockerfile.
$(OPM) index add --generate --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push OPERATOR_IMAGE=$(CATALOG_IMG)

##@ Verify

## Targets to verify actions that generate/modify code have been executed and output committed
Expand Down
6 changes: 6 additions & 0 deletions catalog/authorino-operator-channel-entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
schema: olm.channel
package: authorino-operator
name: stable
entries:
- name: authorino-operator.v0.0.0
9 changes: 9 additions & 0 deletions config/deploy/olm/catalogsource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: authorino-operator-catalog
spec:
sourceType: grpc
image: quay.io/kuadrant/authorino-operator-catalog:local-testing-dd
displayName: Authorino Operator
publisher: grpc
8 changes: 8 additions & 0 deletions config/deploy/olm/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Adds namespace to all resources.
namespace: authorino-operator

resources:
- namespace.yaml
- operatorgroup.yaml
- catalogsource.yaml
- subscription.yaml
6 changes: 6 additions & 0 deletions config/deploy/olm/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: operator
4 changes: 4 additions & 0 deletions config/deploy/olm/operatorgroup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: kuadrant
10 changes: 10 additions & 0 deletions config/deploy/olm/subscription.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: kuadrant
spec:
source: authorino-operator-catalog
sourceNamespace: authorino-operator
name: authorino-operator
channel: "stable"
52 changes: 52 additions & 0 deletions make/catalog.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
##@ Operator Catalog

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(IMAGE_TAG)

CATALOG_FILE = $(PROJECT_DIR)/catalog/authorino-operator-catalog/operator.yaml
CATALOG_DOCKERFILE = $(PROJECT_DIR)/catalog/authorino-operator-catalog.Dockerfile

$(CATALOG_DOCKERFILE): $(OPM)
-mkdir -p $(PROJECT_DIR)/catalog/authorino-operator-catalog
cd $(PROJECT_DIR)/catalog && $(OPM) generate dockerfile authorino-operator-catalog
catalog-dockerfile: $(CATALOG_DOCKERFILE) ## Generate catalog dockerfile.

$(CATALOG_FILE): $(OPM) $(YQ)
@echo "************************************************************"
@echo Build authorino operator catalog
@echo
@echo BUNDLE_IMG = $(BUNDLE_IMG)
@echo CHANNELS = $(CHANNELS)
@echo "************************************************************"
@echo
@echo Please check this matches your expectations and override variables if needed.
@echo
$(PROJECT_DIR)/utils/generate-catalog.sh $(OPM) $(YQ) $(BUNDLE_IMG) $@ $(CHANNELS)

.PHONY: catalog
catalog: $(OPM) ## Generate catalog content and validate.
# Initializing the Catalog
-rm -rf $(PROJECT_DIR)/catalog/authorino-operator-catalog
-rm -rf $(PROJECT_DIR)/catalog/authorino-operator-catalog.Dockerfile
$(MAKE) $(CATALOG_DOCKERFILE)
$(MAKE) $(CATALOG_FILE) BUNDLE_IMG=$(BUNDLE_IMG)
cd $(PROJECT_DIR)/catalog && $(OPM) validate authorino-operator-catalog

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# Ref https://olm.operatorframework.io/docs/tasks/creating-a-catalog/#catalog-creation-with-raw-file-based-catalogs
.PHONY: catalog-build
catalog-build: ## Build a catalog image.
# Build the Catalog
docker build $(PROJECT_DIR)/catalog -f $(PROJECT_DIR)/catalog/authorino-operator-catalog.Dockerfile -t $(CATALOG_IMG)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

deploy-catalog: $(KUSTOMIZE) $(YQ) ## Deploy operator to the K8s cluster specified in ~/.kube/config using OLM catalog image.
didierofrivia marked this conversation as resolved.
Show resolved Hide resolved
V="$(CATALOG_IMG)" $(YQ) eval '.spec.image = strenv(V)' -i config/deploy/olm/catalogsource.yaml
$(KUSTOMIZE) build config/deploy/olm | kubectl apply -f -

undeploy-catalog: $(KUSTOMIZE) ## Undeploy controller from the K8s cluster specified in ~/.kube/config using OLM catalog image.
$(KUSTOMIZE) build config/deploy/olm | kubectl delete -f -
40 changes: 40 additions & 0 deletions utils/generate-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

# Generate OLM catalog file

set -euo pipefail

### CONSTANTS
# Used as well in the subscription object
DEFAULT_CHANNEL=stable
###

OPM="${1?:Error \$OPM not set. Bye}"
YQ="${2?:Error \$YQ not set. Bye}"
BUNDLE_IMG="${3?:Error \$BUNDLE_IMG not set. Bye}"
CATALOG_FILE="${4?:Error \$CATALOG_FILE not set. Bye}"
CHANNELS="${5:-$DEFAULT_CHANNEL}"

CATALOG_FILE_BASEDIR="$( cd "$( dirname ${CATALOG_FILE} )" && pwd )"
CATALOG_BASEDIR="$( cd "$( dirname ${CATALOG_FILE_BASEDIR} )" && pwd )"

TMP_DIR=$(mktemp -d)

${OPM} render ${BUNDLE_IMG} --output=yaml >> ${TMP_DIR}/authorino-operator-bundle.yaml

mkdir -p ${CATALOG_FILE_BASEDIR}
touch ${CATALOG_FILE}

###
# Authorino Operator
###
# Add the package
${OPM} init authorino-operator --default-channel=${CHANNELS} --output yaml >> ${CATALOG_FILE}
# Add a bundles to the Catalog
cat ${TMP_DIR}/authorino-operator-bundle.yaml >> ${CATALOG_FILE}
# Add a channel entry for the bundle
V=`${YQ} eval '.name' ${TMP_DIR}/authorino-operator-bundle.yaml` \
CHANNELS=${CHANNELS} \
${YQ} eval '(.entries[0].name = strenv(V)) | (.name = strenv(CHANNELS))' ${CATALOG_BASEDIR}/authorino-operator-channel-entry.yaml >> ${CATALOG_FILE}

rm -rf $TMP_DIR
Loading