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 4, 2023
1 parent 3170fc3 commit 90652d9
Show file tree
Hide file tree
Showing 5 changed files with 160 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

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

VERSION=$1
BUNDLE_IMAGE=$2

BUNDLE_IMAGE=$BUNDLE_IMAGE:$VERSION
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
BUNDLE_PATH=$SCRIPT_DIR/../olm/$VERSION/

docker build -t $BUNDLE_IMAGE -f $BUNDLE_PATH/bundle.Dockerfile $BUNDLE_PATH
docker push $BUNDLE_IMAGE
54 changes: 54 additions & 0 deletions scripts/create-olm-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -euxo pipefail

# Ex: 21.0.0
VERSION=$1
# Ex: 20.0.0
# Ex: NONE [if no replaces]
REPLACES_VERSION=$2
# Ex: keycloak/keycloak-operator:999.0.0-SNAPSHOT
#OPERATOR_DOCKER_IMAGE=$3

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

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

cd "$SCRIPT_DIR"

rm -rf ../olm/$VERSION
mkdir -p ../olm/$VERSION

# Extract the files generated by Quarkus during the maven build
cp -r ../target/bundle/debezium-operator/* ../olm/$VERSION

# Find the CSV YAML
CSV_PATH="$(find "../olm/$VERSION" -type f -name '*.clusterserviceversion.yaml')"

# Insert operator image coordinate
#yq ea -i ".metadata.annotations.containerImage = \"$OPERATOR_DOCKER_IMAGE:$VERSION\"" "$CSV_PATH"
#yq ea -i ".spec.install.spec.deployments[0].spec.template.spec.containers[0].image = \"$OPERATOR_DOCKER_IMAGE:$VERSION\"" "$CSV_PATH"

# 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"
# yq ea -i '.metadata.namespace = "placeholder"' "$CSV_PATH"

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


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 "Created OLM bundle ok!"
34 changes: 34 additions & 0 deletions scripts/create-olm-test-catalog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/bash
set -euxo pipefail

VERSION=$1
BUNDLE_IMAGE=$2

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

rm -rf $SCRIPT_DIR/../olm/catalog
mkdir -p $SCRIPT_DIR/../olm/catalog/test-catalog

(
cd $SCRIPT_DIR/../olm/catalog

opm generate dockerfile test-catalog

opm init debezium-operator \
--default-channel=alpha \
--output yaml > test-catalog/operator.yaml

opm render $BUNDLE_IMAGE:$VERSION \
--output=yaml >> test-catalog/operator.yaml

cat << EOF >> test-catalog/operator.yaml
---
schema: olm.channel
package: debezium-operator
name: alpha
entries:
- name: debezium-operator.v$VERSION
EOF

opm validate test-catalog
)
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/own

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/own/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



0 comments on commit 90652d9

Please sign in to comment.