From 90652d9eed7783e88b6a7c501425e99e4d46fea4 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 4 Sep 2023 10:51:54 +0200 Subject: [PATCH] DBZ-6738 OLM support scripts --- .gitignore | 5 ++- scripts/create-olm-bundle-image.sh | 12 ++++++ scripts/create-olm-bundle.sh | 54 +++++++++++++++++++++++++++ scripts/create-olm-test-catalog.sh | 34 +++++++++++++++++ scripts/create-olm-test-resources.sh | 56 ++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100755 scripts/create-olm-bundle-image.sh create mode 100755 scripts/create-olm-bundle.sh create mode 100755 scripts/create-olm-test-catalog.sh create mode 100755 scripts/create-olm-test-resources.sh diff --git a/.gitignore b/.gitignore index bf781c7..9a4db10 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,7 @@ nb-configuration.xml /.quarkus/cli/plugins/ # kubernetes -kubernetes.json \ No newline at end of file +kubernetes.json + +# buil dprocess +olm/ \ No newline at end of file diff --git a/scripts/create-olm-bundle-image.sh b/scripts/create-olm-bundle-image.sh new file mode 100755 index 0000000..334a218 --- /dev/null +++ b/scripts/create-olm-bundle-image.sh @@ -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 diff --git a/scripts/create-olm-bundle.sh b/scripts/create-olm-bundle.sh new file mode 100755 index 0000000..222d94e --- /dev/null +++ b/scripts/create-olm-bundle.sh @@ -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!" diff --git a/scripts/create-olm-test-catalog.sh b/scripts/create-olm-test-catalog.sh new file mode 100755 index 0000000..aa95c99 --- /dev/null +++ b/scripts/create-olm-test-catalog.sh @@ -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 +) \ No newline at end of file diff --git a/scripts/create-olm-test-resources.sh b/scripts/create-olm-test-resources.sh new file mode 100755 index 0000000..971a191 --- /dev/null +++ b/scripts/create-olm-test-resources.sh @@ -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 + + +