Skip to content

Commit

Permalink
DBZ-6738 OLM support scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcechace committed Sep 5, 2023
1 parent 3170fc3 commit 61bc202
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ nb-configuration.xml
/.quarkus/cli/plugins/

# kubernetes
kubernetes.json
kubernetes.json

# OLM build workspace
olm/
28 changes: 28 additions & 0 deletions scripts/create-olm-bundle-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/bash
set -euxo pipefail

VERSION=${1:-"all"}
BUNDLE_IMAGE=${2:-"quay.io/debezium/operator-bundle"}
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BUNDLE_BASE_DIR="$SCRIPT_DIR/../olm/bundles"

source "$SCRIPT_DIR/functions.sh"

if [[ $VERSION = "all" ]]
then
BUNDLES=( $BUNDLE_BASE_DIR/*/ )
else
BUNDLES=( "$BUNDLE_BASE_DIR/$VERSION" )
fi


for bundle in "${BUNDLES[@]}"; do
name="$(csvName $bundle)"
version="$(csvVersion $bundle)"
path="$(echo "${bundle%/}")"
image="$BUNDLE_IMAGE:$version"

docker build -t "$image" -f "$path/bundle.Dockerfile" "$path"
docker push "$image"
done;

48 changes: 48 additions & 0 deletions scripts/create-olm-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -euxo pipefail

# Ex: 2.4.1
VERSION=$1
# Ex: 2.4.0
# Ex: none [if no replaces]
REPLACES_VERSION=$2
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BUNDLE_BASE_DIR=$SCRIPT_DIR/../olm/bundles/$VERSION

source "$SCRIPT_DIR/functions.sh"

{ set +x; } 2>/dev/null
echo ""
echo "Creating OLM bundle for version $VERSION replacing version $REPLACES_VERSION"
echo ""
set -x

rm -rf "$BUNDLE_BASE_DIR"
mkdir -p "$BUNDLE_BASE_DIR"

# Copy the files generated by Quarkus during the maven build
pushd $SCRIPT_DIR
cp -r ../target/bundle/debezium-operator/* "$BUNDLE_BASE_DIR"
popd

# Find the CSV YAML
CSV_PATH="$(csvPath "$BUNDLE_BASE_DIR")"

# Edit the CSV version, replaces, etc.
yq ea -i ".metadata.annotations.createdAt = \"$(date "+%D %T")\"" "$CSV_PATH"
yq ea -i ".spec.version = \"$VERSION\"" "$CSV_PATH"
yq ea -i ".metadata.name = \"debezium-operator.v$VERSION\"" "$CSV_PATH"

if [[ $REPLACES_VERSION = "none" ]]
then
yq ea -i "del(.spec.replaces)" "$CSV_PATH"
else
yq ea -i ".spec.replaces = \"debezium-operator.v$REPLACES_VERSION\"" "$CSV_PATH"
fi

# Wire OLM target namespaces and QOSDK configuration together
yq ea -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env += [{"name": "QUARKUS_OPERATOR_SDK_NAMESPACES", "valueFrom": {"fieldRef": {"fieldPath": "metadata.annotations['"'"'olm.targetNamespaces'"'"']"}}}]' "$CSV_PATH"

{ set +x; } 2>/dev/null
echo ""
echo "OLM bundle created!"
61 changes: 61 additions & 0 deletions scripts/create-olm-test-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#! /bin/bash
set -euxo pipefail

VERSION=${1:-"all"}
BUNDLE_IMAGE=${2:-"quay.io/debezium/operator-bundle"}
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CATALOG_NAME="debezium-catalog"
CATALOG_BASE_DIR="$SCRIPT_DIR/../olm/catalog"
CATALOG_DIR="$CATALOG_BASE_DIR/$CATALOG_NAME"
BUNDLE_CATALOG_BASE_DIR="$SCRIPT_DIR/../olm/bundles"

source "$SCRIPT_DIR/functions.sh"

if [[ $VERSION = "all" ]]
then
BUNDLES=( $BUNDLE_CATALOG_BASE_DIR/*/ )
else
BUNDLES=( "$BUNDLE_CATALOG_BASE_DIR/$VERSION" )
fi

rm -rf "$CATALOG_DIR"
rm -rf "$CATALOG_BASE_DIR/$CATALOG_NAME.Dockerfile"
mkdir -p "$CATALOG_DIR"


# Generate dockerfile
opm generate dockerfile "$CATALOG_DIR"

# Initialize catalog manifest
opm init debezium-operator \
--default-channel=alpha \
--output yaml > "$CATALOG_DIR/operator.yal"

# Render each bundle
for bundle in "${BUNDLES[@]}"; do
version="$(csvVersion $bundle)"
image="$BUNDLE_IMAGE:$version"
echo "Rendering bundle for $image"
opm render "$image" --output=yaml >> "$CATALOG_DIR/operator.yal"
done;

# Write out channel declaration
cat << EOF >> "$CATALOG_DIR/operator.yal"
---
schema: olm.channel
package: debezium-operator
name: alpha
entries:
EOF

# Write out channel entries
for bundle in "${BUNDLES[@]}"; do
name="$(csvName $bundle)"
replaces="$(csvReplaces $bundle)"

echo " - name: $name" >> "$CATALOG_DIR/operator.yal"
[ $replaces != "null" ] && echo " replaces: $replaces" >> "$CATALOG_DIR/operator.yal"
done;

# Validate generated catalog
opm validate "$CATALOG_DIR"
56 changes: 56 additions & 0 deletions scripts/create-olm-test-resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#! /bin/bash
set -euxo pipefail

VERSION=$1
CATALOG_IMAGE=${2:-"quay.io/debezium/operator-catalog:latest"}


SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

rm -rf "$SCRIPT_DIR/../olm/testing-resources"
mkdir -p "$SCRIPT_DIR/../olm/testing-resources"

cat << EOF >> "$SCRIPT_DIR/../olm/testing-resources/catalog.yaml"
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: debezium-catalog
namespace: olm
spec:
grpcPodConfig:
securityContextConfig: restricted
sourceType: grpc
image: $CATALOG_IMAGE
displayName: Debezium Test Catalog
publisher: Me
updateStrategy:
registryPoll:
interval: 10m
EOF


cat << EOF >> "$SCRIPT_DIR/../olm/testing-resources/operatorgroup.yaml"
kind: OperatorGroup
apiVersion: operators.coreos.com/v1
metadata:
name: og-own
spec:
targetNamespaces:
- debezium
EOF

cat << EOF >> "$SCRIPT_DIR/../olm/testing-resources/subscription.yaml"
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: debezium-operator
spec:
installPlanApproval: Automatic
name: debezium-operator
source: debezium-catalog
sourceNamespace: olm
startingCSV: debezium-operator.v$VERSION
EOF



17 changes: 17 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

function csvPath() {
find "$1" -type f -name '*.clusterserviceversion.yaml'
}

function csvName() {
yq ".metadata.name" $(csvPath $1)
}

function csvVersion() {
yq ".spec.version" $(csvPath $1)
}

function csvReplaces() {
yq ".spec.replaces" $(csvPath $1)
}

0 comments on commit 61bc202

Please sign in to comment.