Skip to content

Commit c04506b

Browse files
Build olm catalog
1 parent 4bf5755 commit c04506b

4 files changed

Lines changed: 108 additions & 17 deletions

File tree

.github/workflows/release.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
3333
- name: Build operator image
3434
run: make docker-buildx
35-
release-operator-bundle-image:
35+
36+
release-operator-olm-images:
3637
runs-on: ubuntu-latest
3738
steps:
3839
- name: Checkout code
@@ -43,10 +44,17 @@ jobs:
4344
registry: ${{ env.REGISTRY }}
4445
username: ${{ github.actor }}
4546
password: ${{ secrets.GITHUB_TOKEN }}
47+
- name: Install jq
48+
uses: dcarbone/install-jq-action@v3.2.0
4649
- name: Set VERSION
4750
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
4851
- name: Build operator bundle image
4952
run: make bundle bundle-buildx
53+
- name: Build catalog
54+
run: make catalog-buildx
55+
- name: Mark catalog as latest
56+
run: make catalog-push-latest
57+
5058
release-operator-helm-chart:
5159
runs-on: ubuntu-latest
5260
steps:
@@ -64,11 +72,12 @@ jobs:
6472
run: |
6573
helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
6674
make push-helmchart
75+
6776
create-release:
6877
runs-on: ubuntu-latest
6978
needs:
7079
- release-operator-image
71-
- release-operator-bundle-image
80+
- release-operator-olm-images
7281
- release-operator-helm-chart
7382
steps:
7483
- name: Checkout code
@@ -115,23 +124,21 @@ jobs:
115124
with:
116125
tag_name: ${{ github.ref_name }}
117126
name: ${{github.ref_name }}
127+
draft: true
118128
body: |
119-
## Pull the latest operator images
120-
```
121-
docker pull ghcr.io/clickhouse/clickhouse-operator/clickhouse-operator:${{ github.ref_name }}
122-
docker pull ghcr.io/clickhouse/clickhouse-operator/clickhouse-operator-bundle:${{ github.ref_name }}
123-
```
124129
## Install using the manifest
125130
```
126131
kubectl apply -f https://github.com/ClickHouse/clickhouse-operator/releases/download/${{github.ref_name}}/clickhouse-operator.yaml
127132
```
133+
128134
## Install using helmchart
129135
```
130136
helm install clickhouse-operator oci://ghcr.io/clickhouse/clickhouse-operator-helm \
131137
--version=${{env.VERSION}} \
132138
--create-namespace \
133139
-n clickhouse-operator-system
134140
```
141+
135142
## Changelog
136143
${{steps.build_changelog.outputs.changelog}}
137144
generate_release_notes: false

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ dist/chart/charts
1212
clickhouse-operator-helm-*.tgz
1313
clickhouse-operator_*.tar.gz
1414
bundle
15+
*.Dockerfile.cross
16+
17+
# Artidfacts for building OLM catalog
18+
catalog
19+
catalog.Dockerfile
1520

1621
# Test binary, built with `go test -c`
1722
*.test

Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ endif
5555
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5656
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
5757
OPERATOR_SDK_VERSION ?= v1.42.0
58+
OPERATOR_MANAGER_VERSION ?= v1.62.0
5859
# Image URL to use all building/pushing image targets
5960
IMG ?= ${IMAGE_TAG_BASE}:${FULL_VERSION}
6061
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
@@ -397,18 +398,14 @@ ifeq (,$(shell which opm 2>/dev/null))
397398
set -e ;\
398399
mkdir -p $(dir $(OPM)) ;\
399400
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
400-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
401+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/${OPERATOR_MANAGER_VERSION}/$${OS}-$${ARCH}-opm ;\
401402
chmod +x $(OPM) ;\
402403
}
403404
else
404405
OPM = $(shell which opm)
405406
endif
406407
endif
407408

408-
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
409-
# These images MUST exist in a registry and be pull-able.
410-
BUNDLE_IMGS ?= $(BUNDLE_IMG)
411-
412409
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
413410
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:$(FULL_VERSION)
414411

@@ -417,12 +414,34 @@ ifneq ($(origin CATALOG_BASE_IMG), undefined)
417414
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
418415
endif
419416

420-
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
421-
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
422-
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
417+
.PHONY: catalog-dockerfile
418+
catalog-dockerfile: opm ## Generate catalog Dockerfile
419+
rm -f catalog.Dockerfile && $(OPM) generate dockerfile catalog
420+
421+
.PHONY: catalog-template
422+
catalog-template: # Generate catalog template with all bundles from registry
423+
./ci/generate-catalog-template.sh $(IMAGE_TAG_BASE)-bundle
424+
425+
catalog-render: opm catalog-template ## Genermrate FBC catalog from template
426+
$(OPM) alpha render-template catalog/clickhouse-operator-template.yaml > catalog/catalog.yaml
427+
$(OPM) validate catalog
428+
423429
.PHONY: catalog-build
424-
catalog-build: opm ## Build a catalog image.
425-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
430+
catalog-build: catalog-render catalog-dockerfile ## Build a catalog image using FBC
431+
$(CONTAINER_TOOL) build -f catalog.Dockerfile -t $(CATALOG_IMG) .
432+
433+
.PHONY: catalog-buildx
434+
catalog-buildx: catalog-render catalog-dockerfile ## Build and push catalog image for cross-platform support
435+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' catalog.Dockerfile > catalog.Dockerfile.cross
436+
- $(CONTAINER_TOOL) buildx create --name clickhouse-operator-catalog-builder
437+
$(CONTAINER_TOOL) buildx use clickhouse-operator-catalog-builder
438+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag $(CATALOG_IMG) -f catalog.Dockerfile.cross .
439+
- $(CONTAINER_TOOL) buildx rm clickhouse-operator-catalog-builder
440+
rm -f catalog.Dockerfile.cross
441+
442+
.PHONY: catalog-push-latest
443+
catalog-push-latest:
444+
$(CONTAINER_TOOL) buildx imagetools create -t $(IMAGE_TAG_BASE)-catalog:latest $(CATALOG_IMG)
426445

427446
# Push the catalog image.
428447
.PHONY: catalog-push

ci/generate-catalog-template.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Generate OLM catalog template with all available bundles from registry
5+
# Usage: ./ci/generate-catalog-template.sh [<bundle-image>]
6+
7+
# Image repository
8+
BUNDLE_IMAGE=${1-ghcr.io/clickhouse/clickhouse-operator-bundle}
9+
# Output file
10+
OUTPUT_FILE="catalog/clickhouse-operator-template.yaml"
11+
12+
# Function to get all tags from ghcr.io
13+
get_bundle_tags() {
14+
local owner="clickhouse"
15+
local gh_api_url="https://api.github.com/orgs/clickhouse/packages/container/clickhouse-operator-bundle/versions"
16+
17+
echo "Fetching bundle tags from ${BUNDLE_IMAGE}" >&2
18+
curl -sL \
19+
-H "Accept: application/vnd.github+json" \
20+
-H "X-GitHub-Api-Version: 2022-11-28" \
21+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
22+
"${gh_api_url}" 2>/dev/null \
23+
| jq -r '.[].metadata.container.tags[]' 2>/dev/null \
24+
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
25+
| sort -V
26+
}
27+
28+
# Get all bundle tags
29+
BUNDLE_TAGS=$(get_bundle_tags)
30+
31+
if [ -z "$BUNDLE_TAGS" ]; then
32+
echo "Error: No bundle tags found in registry"
33+
exit 1
34+
fi
35+
36+
echo "Found bundle tags:"
37+
echo "$BUNDLE_TAGS"
38+
39+
# Create catalog directory if it doesn't exist
40+
mkdir -p catalog
41+
42+
# Generate the template YAML
43+
cat > "$OUTPUT_FILE" <<EOF
44+
Schema: olm.semver
45+
GenerateMajorChannels: true
46+
GenerateMinorChannels: false
47+
Stable:
48+
Bundles:
49+
EOF
50+
51+
for tag in $BUNDLE_TAGS; do
52+
if [ -n "$tag" ]; then
53+
echo " - Image: ${BUNDLE_IMAGE}:${tag}" >> "$OUTPUT_FILE"
54+
fi
55+
done
56+
57+
echo ""
58+
echo "Generated catalog template at: $OUTPUT_FILE"
59+
echo "Contents:"
60+
cat "$OUTPUT_FILE"

0 commit comments

Comments
 (0)