Skip to content

Commit

Permalink
File-based OLM catalog with history (#1308)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Jan 7, 2025
1 parent eecac85 commit 9883b2c
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 53 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Set Image Tag Env
run: echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Operator Version Check
run: ./operator/bin/version-check.sh "${{ env.PROJECT_VERSION }}"

- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -98,7 +101,7 @@ jobs:
# ==================== Operator-Bundle ====================
- name: Modify Bundle CSV Metadata
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{ env.PROJECT_VERSION }}" "SKIP_RANGE=>=0.0.1 <${{ env.PROJECT_VERSION }}"
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{ env.PROJECT_VERSION }}"

- name: Build Operator Bundle Image
uses: docker/build-push-action@v6
Expand All @@ -118,17 +121,17 @@ jobs:
chmod +x opm
sudo cp -v opm /usr/bin/
rm -vf opm
operator/bin/generate-catalog.sh ${{ env.PROJECT_VERSION }}
operator/bin/generate-catalog.sh localhost:5000/streamshub/console-operator-bundle true
- name: Build Operator Catalog Image
uses: docker/build-push-action@v6
with:
context: operator/target/
context: operator/
platforms: ${{ env.PLATFORMS }}
network: none
provenance: false
push: true
file: operator/target/catalog.Dockerfile
file: operator/src/main/docker/catalog.Dockerfile
tags: |
localhost:5000/streamshub/console-operator-catalog:${{ env.PROJECT_VERSION }}
Expand Down
25 changes: 18 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,27 @@ jobs:
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b release
mvn -B release:prepare -DreleaseVersion=${{steps.metadata.outputs.current-version}} -DdevelopmentVersion=${{steps.metadata.outputs.next-version}}
git checkout ${{github.base_ref}}
git rebase release
PRERELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr '[:upper:]' '[:lower:]')
export QUARKUS_CONTAINER_IMAGE_REGISTRY="${{ secrets.IMAGE_REPO_HOSTNAME }}"
export QUARKUS_CONTAINER_IMAGE_GROUP="${{ secrets.IMAGE_REPO_NAMESPACE }}"
export QUARKUS_CONTAINER_IMAGE_USERNAME="${{ secrets.IMAGE_REPO_USERNAME }}"
export QUARKUS_CONTAINER_IMAGE_PASSWORD="${{ secrets.IMAGE_REPO_PASSWORD }}"
export QUARKUS_CONTAINER_IMAGE_PUSH="true"
export QUARKUS_CONTAINER_IMAGE_ADDITIONAL_TAGS=latest
export QUARKUS_KUBERNETES_NAMESPACE='$${NAMESPACE}'
mvn -B release:prepare \
-DprereleaseVersion=${PRERELEASE_VERSION} \
-DreleaseVersion=${{ steps.metadata.outputs.current-version }} \
-DdevelopmentVersion=${{ steps.metadata.outputs.next-version }} \
-Dcontainer-image.registry=${{ secrets.IMAGE_REPO_HOSTNAME }}
git checkout ${{github.base_ref}}
git rebase release
export GIT_REVISION=$(git rev-parse --short release)
# Build and push the release images using the commit tagged in `release:prepare`
mvn -B -P container-image release:perform --no-transfer-progress \
'-Drelease.arguments=-Dquarkus.docker.buildx.platform=${{ env.PLATFORMS }}'
Expand Down Expand Up @@ -94,7 +104,7 @@ jobs:
# ==================== Operator-Bundle ====================
- name: Modify Bundle CSV Metadata
working-directory: target/checkout
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{steps.metadata.outputs.current-version}}" "SKIP_RANGE=>=0.0.1 <${{steps.metadata.outputs.current-version}}"
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{steps.metadata.outputs.current-version}}"

- name: Build and Push Operator Bundle Image
uses: docker/build-push-action@v6
Expand All @@ -116,17 +126,18 @@ jobs:
chmod +x opm
sudo cp -v opm /usr/bin/
rm -vf opm
operator/bin/generate-catalog.sh ${{steps.metadata.outputs.current-version}}
operator/bin/generate-catalog.sh \
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-bundle
- name: Build and Push Operator Catalog Image
uses: docker/build-push-action@v6
with:
context: target/checkout/operator/target/
context: target/checkout/operator/
platforms: ${{ env.PLATFORMS }}
network: none
provenance: false
push: true
file: target/checkout/operator/target/catalog.Dockerfile
file: target/checkout/operator/src/main/docker/catalog.Dockerfile
tags: |
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-catalog:${{steps.metadata.outputs.current-version}}
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-catalog:latest
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
# ==================== Operator-Bundle ====================
- name: Modify Bundle CSV Metadata
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{ env.NEXT_VERSION }}" "SKIP_RANGE=>=0.0.1 <${{ env.NEXT_VERSION }}"
run: ./operator/bin/modify-bundle-metadata.sh "VERSION=${{ env.NEXT_VERSION }}"

- name: Build and Push Operator Bundle Image
uses: docker/build-push-action@v6
Expand All @@ -119,17 +119,18 @@ jobs:
chmod +x opm
sudo cp -v opm /usr/bin/
rm -vf opm
operator/bin/generate-catalog.sh ${{ env.NEXT_VERSION }}
operator/bin/generate-catalog.sh \
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-bundle
- name: Build and Push Operator Catalog Image
uses: docker/build-push-action@v6
with:
context: operator/target/
context: operator/
platforms: ${{ env.PLATFORMS }}
network: none
provenance: false
push: true
file: operator/target/catalog.Dockerfile
file: operator/src/main/docker/catalog.Dockerfile
tags: |
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-catalog:${{ env.NEXT_VERSION }}
${{ secrets.IMAGE_REPO_HOSTNAME }}/${{ secrets.IMAGE_REPO_NAMESPACE }}/console-operator-catalog:snapshot-${{github.ref_name}}
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CONSOLE_OPERATOR_CATALOG_IMAGE ?= $(IMAGE_REGISTRY)/$(IMAGE_GROUP)/console-opera
CONTAINER_RUNTIME ?= $(shell which podman || which docker)
SKOPEO_TRANSPORT ?= $(shell which podman >/dev/null && echo "containers-storage:" || echo "docker-daemon:")
ARCH ?= linux/amd64
SKIP_RANGE ?= ">=1.0.0 <1.0.3"
SKIP_RANGE ?= ""

CONSOLE_UI_NEXTAUTH_SECRET ?= $(shell openssl rand -base64 32)

Expand All @@ -36,9 +36,9 @@ container-image-api-push: container-image-api
container-image-operator:
mvn package -am -pl operator -Pcontainer-image -DskipTests -Dquarkus.kubernetes.namespace='$${NAMESPACE}' -Dquarkus.container-image.image=$(CONSOLE_OPERATOR_IMAGE)
operator/bin/modify-bundle-metadata.sh "VERSION=$(CSV_VERSION)" "SKIP_RANGE=$(SKIP_RANGE)" "SKOPEO_TRANSPORT=$(SKOPEO_TRANSPORT)"
operator/bin/generate-catalog.sh $(CSV_VERSION)
operator/bin/generate-catalog.sh operator/target/bundle/streamshub-console-operator
$(CONTAINER_RUNTIME) build --platform=$(ARCH) -t $(CONSOLE_OPERATOR_BUNDLE_IMAGE) -f operator/target/bundle/streamshub-console-operator/bundle.Dockerfile
$(CONTAINER_RUNTIME) build --platform=$(ARCH) -t $(CONSOLE_OPERATOR_CATALOG_IMAGE) -f operator/target/catalog.Dockerfile
$(CONTAINER_RUNTIME) build --platform=$(ARCH) -t $(CONSOLE_OPERATOR_CATALOG_IMAGE) -f operator/src/main/docker/catalog.Dockerfile operator

container-image-operator-push: container-image-operator
skopeo copy --preserve-digests $(SKOPEO_TRANSPORT)$(CONSOLE_OPERATOR_IMAGE) docker://$(CONSOLE_OPERATOR_IMAGE)
Expand Down
15 changes: 3 additions & 12 deletions operator/bin/common.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
#!/bin/bash

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"

BUNDLE_PATH=${SCRIPT_PATH}/../target/bundle/streamshub-console-operator/
CSV_FILE_PATH=${BUNDLE_PATH}/manifests/streamshub-console-operator.clusterserviceversion.yaml
CATALOG_PATH=${SCRIPT_PATH}/../target/catalog
OPERATOR_CATALOG_CONFIG_YAML_PATH=${CATALOG_PATH}/operator.yaml
# Operator naming
ORIGINAL_OPERATOR_NAME="console-operator"
OPERATOR_NAME="streamshub-console-operator"
OPERATOR_INSTANCE_NAME="${OPERATOR_NAME}-v${VERSION}"
OPERATOR_CSV_NAME="${OPERATOR_NAME}.v${VERSION}"

YQ="$(which yq 2>/dev/null)" || :

if [ "${YQ}" == "" ] ; then
Expand All @@ -25,3 +13,6 @@ if [ "${SKOPEO}" == "" ] ; then
echo "'skopeo' is not installed, please visit https://github.com/containers/skopeo/blob/main/install.md for more info"
exit 1
fi

# Operator naming
OPERATOR_NAME="streamshub-console-operator"
44 changes: 25 additions & 19 deletions operator/bin/generate-catalog.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
#!/bin/bash

set -xEeuo pipefail

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"

export VERSION="${1}"
export CONSOLE_OPERATOR_BUNDLE="${1:-}"
export USE_HTTP="${2:-false}"

source ${SCRIPT_PATH}/common.sh
OPERATOR_PATH="$(cd -- "${SCRIPT_PATH}/.." >/dev/null 2>&1 ; pwd -P)"
CATALOG_PATH=${OPERATOR_PATH}/target/catalog

echo "[INFO] Generate catalog"

rm -rvf ${CATALOG_PATH} ${CATALOG_PATH}.Dockerfile
echo "[INFO] Generate catalog in ${CATALOG_PATH}"
rm -rvf ${CATALOG_PATH}
mkdir -p ${CATALOG_PATH}
cp -v ${OPERATOR_PATH}/src/main/olm/*.yaml ${CATALOG_PATH}/

for CSV_NAME in $(${YQ} '.entries[].name' ${CATALOG_PATH}/channel.alpha.yaml | sort -V) ; do
if [ -f ${OPERATOR_PATH}/src/main/olm/bundles/${CSV_NAME}.yaml ] ; then
BUNDLE_IMAGE=$(${YQ} '.image' ${OPERATOR_PATH}/src/main/olm/bundles/${CSV_NAME}.yaml)
elif [ -d ${CONSOLE_OPERATOR_BUNDLE} ] ; then
BUNDLE_IMAGE=${CONSOLE_OPERATOR_BUNDLE}
else
BUNDLE_IMAGE=${CONSOLE_OPERATOR_BUNDLE}:$(echo "${CSV_NAME}" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+(-snapshot)?$')
fi

opm generate dockerfile ${CATALOG_PATH}
opm init ${OPERATOR_NAME} --default-channel=alpha --output=yaml > ${OPERATOR_CATALOG_CONFIG_YAML_PATH}
opm render ${BUNDLE_PATH} --output=yaml >> ${OPERATOR_CATALOG_CONFIG_YAML_PATH}
RENDER_FLAGS='--output=yaml'

cat << EOF >> ${OPERATOR_CATALOG_CONFIG_YAML_PATH}
---
schema: olm.channel
package: ${OPERATOR_NAME}
name: alpha
entries:
- name: ${OPERATOR_CSV_NAME}
EOF
if [ "${USE_HTTP}" == "true" ] ; then
RENDER_FLAGS="--use-http ${RENDER_FLAGS}"
fi

# Rename package names
${YQ} eval -o yaml -i ". |= select(.package == \"${ORIGINAL_OPERATOR_NAME}\").package = \"${OPERATOR_NAME}\"" "${OPERATOR_CATALOG_CONFIG_YAML_PATH}"
${YQ} eval -o yaml -i "(.properties[] | select(.value.packageName == \"${ORIGINAL_OPERATOR_NAME}\") | .value.packageName) = \"${OPERATOR_NAME}\"" "${OPERATOR_CATALOG_CONFIG_YAML_PATH}"
opm render ${BUNDLE_IMAGE} ${RENDER_FLAGS} > ${CATALOG_PATH}/${CSV_NAME}.yaml
done

opm validate ${CATALOG_PATH}

echo "[DEBUG] Catalog generated"
echo "[DEBUG] Catalog generated"
17 changes: 14 additions & 3 deletions operator/bin/modify-bundle-metadata.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
#!/bin/bash

set -xEeuo pipefail

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"

VERSION=""
SKIP_RANGE=""
SKOPEO_TRANSPORT="docker://"

for ARGUMENT in "$@"
do
for ARGUMENT in "$@" ; do
KEY=$(echo "$ARGUMENT" | sed 's/=\(.*\)//')
VALUE=$(echo "$ARGUMENT" | sed 's/^[^=]*=//')

case "$KEY" in
VERSION) VERSION=${VALUE};;
SKIP_RANGE) SKIP_RANGE=${VALUE};;
ORIGINAL_OPERATOR_NAME) ORIGINAL_OPERATOR_NAME=${VALUE};;
SKOPEO_TRANSPORT) SKOPEO_TRANSPORT=${VALUE};;
*)
esac
done

if [ -z "${VERSION}" ] ; then
echo "[ERROR] VERSION required"
exit 1
fi

source ${SCRIPT_PATH}/common.sh

OPERATOR_INSTANCE_NAME="${OPERATOR_NAME}-v${VERSION}"
OPERATOR_CSV_NAME="${OPERATOR_NAME}.v${VERSION}"

BUNDLE_PATH=${SCRIPT_PATH}/../target/bundle/streamshub-console-operator/
CSV_FILE_PATH=${BUNDLE_PATH}/manifests/streamshub-console-operator.clusterserviceversion.yaml

api_name="console-api"
ui_name="console-ui"
operator_name="console-operator"
Expand Down
48 changes: 48 additions & 0 deletions operator/bin/release-prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

set -xEeuo pipefail

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
OPERATOR_PATH="$(cd -- "${SCRIPT_PATH}/.." >/dev/null 2>&1 ; pwd -P)"

PRERELEASE_VERSION="${1?prerelease version is required}"
RELEASE_VERSION="${2?release version is required}"
POSTRELEASE_VERSION="${3?postrelease version is required}"
VERSION="${4?current version is required}"
IMAGE_NAME="${5?image name is required}"
GIT_STAGE="${6:-false}"

source ${SCRIPT_PATH}/common.sh

PRERELEASE_CSV_NAME="${OPERATOR_NAME}.v${PRERELEASE_VERSION}"
RELEASE_CSV_NAME="${OPERATOR_NAME}.v${RELEASE_VERSION}"
POSTRELEASE_CSV_NAME="${OPERATOR_NAME}.v${POSTRELEASE_VERSION}"

if [ "${VERSION}" == "${POSTRELEASE_VERSION}" ] ; then
# Running via the `completionGoals` of the maven-release-plugin
echo "[INFO] Running release completion with version ${VERSION}"

# Create new entry for the next development cycle, "replaces" the version just released
${YQ} -i '.entries += {
"name": "'${POSTRELEASE_CSV_NAME}'",
"replaces": "'${RELEASE_CSV_NAME}'"
}' ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml

if [ "${GIT_STAGE}" == "true" ] ; then
git add ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml
fi
else
# Running via the `preparationGoals` of the maven-release-plugin
echo "[INFO] Running release preparation for version ${VERSION}"

# Change the name of the entry to be the released version (e.g removing the -snapshot suffix)
${YQ} -i '(.entries[].name | select(. == "'${PRERELEASE_CSV_NAME}'")) = "'${RELEASE_CSV_NAME}'"' \
${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml

# Create a file with a reference to the bundle image to be generated during the release
echo "image: ${IMAGE_NAME}:${VERSION}" > ${OPERATOR_PATH}/src/main/olm/bundles/${RELEASE_CSV_NAME}.yaml

if [ "${GIT_STAGE}" == "true" ] ; then
git add ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml ${OPERATOR_PATH}/src/main/olm/bundles/${RELEASE_CSV_NAME}.yaml
fi
fi
20 changes: 20 additions & 0 deletions operator/bin/version-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -xEeuo pipefail

SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
OPERATOR_PATH="$(cd -- "${SCRIPT_PATH}/.." >/dev/null 2>&1 ; pwd -P)"

VERSION="${1?version is required}"

source ${SCRIPT_PATH}/common.sh
OPERATOR_CSV_NAME="${OPERATOR_NAME}.v${VERSION}"
ALPHA_CHANNEL=${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml

if [ "$(${YQ} '(.entries[].name | select(. == "'${OPERATOR_CSV_NAME}'"))' ${ALPHA_CHANNEL})" != "" ] ; then
echo "[INFO] Bundle ${OPERATOR_CSV_NAME} has an entry in ${ALPHA_CHANNEL}"
exit 0;
fi

echo "[ERROR] Bundle ${OPERATOR_CSV_NAME} has no entry in ${ALPHA_CHANNEL}"
exit 1;
33 changes: 33 additions & 0 deletions operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,38 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>release-preparation</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>olm-channel-update</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bin/release-prepare.sh</executable>
<arguments>
<argument>${prereleaseVersion}</argument>
<argument>${releaseVersion}</argument>
<argument>${developmentVersion}</argument>
<argument>${project.version}</argument>
<argument>${container-image.registry}/${container-image.group}/console-operator-bundle</argument>
<!-- stage to git index -->
<argument>true</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit 9883b2c

Please sign in to comment.