From 5895582c947a5323dc2fbe9eb3235b083290bf7c Mon Sep 17 00:00:00 2001 From: jcechace Date: Thu, 3 Aug 2023 12:19:38 +0200 Subject: [PATCH 1/6] DBZ-6738 Suport for watching all namespaces with OLM installation --- README.md | 7 +- k8/kubernetes.yml | 27 ++++-- pom.xml | 31 ++++++- .../operator/DebeziumCsvMetadata.java | 93 +++++++++++++++++++ .../operator/DebeziumServerReconciler.java | 9 +- .../dependent/RoleBindingDependent.java | 14 ++- .../operator/dependent/RoleDependent.java | 38 ++++++++ .../dependent/ServiceAccountDependent.java | 2 +- src/main/kubernetes/debezium-icon.svg | 1 + 9 files changed, 199 insertions(+), 23 deletions(-) create mode 100644 src/main/java/io/debezium/operator/DebeziumCsvMetadata.java create mode 100644 src/main/java/io/debezium/operator/dependent/RoleDependent.java create mode 100644 src/main/kubernetes/debezium-icon.svg diff --git a/README.md b/README.md index 051118d..9e1724d 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,15 @@ Debezium operator provides an easy way to run the Debezium Server on Kubernetes or Openshift. ## Installation steps - -The debezium operator currently support per namespace installation. To install the operator to your kubernetes cluster, +The debezium operator currently support only per namespace installation unless installing via OLM. To install the operator to your kubernetes cluster, simply create the descriptors available in the `k8` directory. ```bash -kubectl create -f k8/ -n $NAMESPACE +kubectl create -f k8/ -n $NAMESPACE ``` +_Note: In the future the operator will support OLM and Helm chart installations._ + ### Quickstart Example The `exmaples/postgres` directory contains an example deployment of debezium server with PostgreSQL source and kafka diff --git a/k8/kubernetes.yml b/k8/kubernetes.yml index e012f04..5336f0e 100644 --- a/k8/kubernetes.yml +++ b/k8/kubernetes.yml @@ -3,8 +3,8 @@ apiVersion: v1 kind: ServiceAccount metadata: labels: - app.kubernetes.io/name: debezium-operator app.kubernetes.io/managed-by: quarkus + app.kubernetes.io/name: debezium-operator name: debezium-operator --- apiVersion: rbac.authorization.k8s.io/v1 @@ -49,10 +49,10 @@ rules: - get - list - watch - - create - patch - update - delete + - create - apiGroups: - rbac.authorization.k8s.io resources: @@ -61,10 +61,22 @@ rules: - get - list - watch + - patch + - update + - delete - create + - apiGroups: + - rbac.authorization.k8s.io + resources: + - roles + verbs: + - get + - list + - watch - patch - update - delete + - create - apiGroups: - "" resources: @@ -73,10 +85,10 @@ rules: - get - list - watch - - create - patch - update - delete + - create - apiGroups: - apps resources: @@ -85,10 +97,10 @@ rules: - get - list - watch - - create - patch - update - delete + - create --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding @@ -151,8 +163,8 @@ apiVersion: apps/v1 kind: Deployment metadata: labels: - app.kubernetes.io/name: debezium-operator app.kubernetes.io/managed-by: quarkus + app.kubernetes.io/name: debezium-operator name: debezium-operator spec: replicas: 1 @@ -162,8 +174,8 @@ spec: template: metadata: labels: - app.kubernetes.io/name: debezium-operator app.kubernetes.io/managed-by: quarkus + app.kubernetes.io/name: debezium-operator spec: containers: - env: @@ -185,9 +197,6 @@ spec: timeoutSeconds: 10 name: debezium-operator ports: - - containerPort: 8443 - name: https - protocol: TCP - containerPort: 8080 name: http protocol: TCP diff --git a/pom.xml b/pom.xml index aaff174..4ccaace 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ ${project.version} + ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x 3.11.0 17 @@ -29,9 +30,9 @@ UTF-8 UTF-8 quarkus-bom - io.quarkus.platform - 3.0.1.Final - 6.1.0 + io.quarkus + 3.2.4.Final + 6.3.0 true 3.0.0 3.24.2 @@ -39,7 +40,6 @@ false ${project.artifactId} - alpha quay.io debezium operator @@ -120,6 +120,20 @@ + + org.codehaus.mojo + build-helper-maven-plugin + 3.4.0 + + + initialize + parse-version + + parse-version + + + + ${quarkus.platform.group-id} quarkus-maven-plugin @@ -194,6 +208,15 @@ stable ${project.parent.version} + debezium-${version.debezium.channel} + + + + + + olmStable + + debezium-stable,debezium-${version.debezium.channel} diff --git a/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java new file mode 100644 index 0000000..4a61a51 --- /dev/null +++ b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java @@ -0,0 +1,93 @@ +/* + * Copyright Debezium Authors. + * + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package io.debezium.operator; + +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Annotations; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Icon; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.InstallMode; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Link; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Maintainer; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Provider; +import io.quarkiverse.operatorsdk.bundle.runtime.SharedCSVMetadata; + +// @formatter:off +@CSVMetadata( + name = DebeziumCsvMetadata.NAME, + displayName = "Debezium Operator", + version = "${olm.bundle.version}", replaces = "${olm.bundle.replaces}", + icon = @Icon(fileName = "debezium-icon.svg"), + provider = @Provider(name = "Debezium Authors", url = "https://debezium.io/"), + maintainers = @Maintainer(name = "Debezium Authors", email = "debezium@googlegroups.com"), + keywords = { + "Debezium", + "CDC", + "Data", + "Streaming"}, + links = { + @Link(url = "https://debezium.io/", name = "Debezium"), + @Link(url = "https://debezium.io/documentation/reference/stable/", name = "Documentation"), + @Link(url = "debezium.zulipchat.com", name = "Debezium Zulip Chat")}, + installModes = { + @InstallMode(type = "OwnNamespace"), + @InstallMode(type = "SingleNamespace"), + @InstallMode(type = "AllNamespaces"), + @InstallMode(type = "MultiNamespace")}, + annotations = @Annotations( + capabilities = "Basic Install", + categories = "Big Data, Database, Integration & Delivery, Streaming & Messaging", + containerImage = "${olm.bundle.containerImage}", + others = { + @Annotations.Annotation( + name = "createdAt", + value = "${olm.bundle.createdAt}"), + @Annotations.Annotation( + name = "support", + value = "Debezium Authors"), + @Annotations.Annotation( + name = "description", + value = "An Operator for installing and managing Debezium")}, + almExamples =""" + [ + { + "apiVersion": "debezium.io/v1alpha1", + "kind": "DebeziumServer", + "metadata": { + "name": "debezium-test" + }, + "spec": { + "quarkus": { + "config": { + "log.console.json": false + } + }, + "sink": { + "type": "kafka", + "config": { + "producer.bootstrap.servers": "dbz-kafka-kafka-bootstrap.debezium:9092", + "producer.key.serializer": "org.apache.kafka.common.serialization.StringSerializer", + "producer.value.serializer": "org.apache.kafka.common.serialization.StringSerializer" + } + }, + "source": { + "class": "io.debezium.connector.mongodb.MongoDbConnector", + "config": { + "topic.prefix": "dbserver1", + "offset.storage.file.filename": "/debezium/data/offsets.dat", + "database.history": "io.debezium.relational.history.FileDatabaseHistory", + "mongodb.connection.string": "mongodb://debezium:dbz@mongo.debezium:27017/?replicaSet=rs0" + } + } + } + } + ] + """), + description = "Debezium is an open source distributed platform for change data capture. " + + "Start it up, point it at your databases, and your apps can start responding " + + "to all of the inserts, updates, and deletes that other apps commit to your databases") +public class DebeziumCsvMetadata implements SharedCSVMetadata { + public static final String NAME = "debezium-operator"; +} diff --git a/src/main/java/io/debezium/operator/DebeziumServerReconciler.java b/src/main/java/io/debezium/operator/DebeziumServerReconciler.java index 641d625..7374cd7 100644 --- a/src/main/java/io/debezium/operator/DebeziumServerReconciler.java +++ b/src/main/java/io/debezium/operator/DebeziumServerReconciler.java @@ -12,6 +12,7 @@ import io.debezium.operator.dependent.ConfigMapDependent; import io.debezium.operator.dependent.DeploymentDependent; import io.debezium.operator.dependent.RoleBindingDependent; +import io.debezium.operator.dependent.RoleDependent; import io.debezium.operator.dependent.ServiceAccountDependent; import io.debezium.operator.dependent.conditions.DeploymentReady; import io.debezium.operator.model.status.Condition; @@ -22,17 +23,23 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; +import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata; import io.quarkus.logging.Log; @ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE, name = "debeziumserver", dependents = { @Dependent(name = "service-account", type = ServiceAccountDependent.class), - @Dependent(name = "role-binding", type = RoleBindingDependent.class, dependsOn = { "service-account" }), + @Dependent(name = "role", type = RoleDependent.class), + @Dependent(name = "role-binding", type = RoleBindingDependent.class, dependsOn = { + "service-account", + "role" + }), @Dependent(name = "config", type = ConfigMapDependent.class), @Dependent(name = "deployment", type = DeploymentDependent.class, dependsOn = { "config", "role-binding" }, readyPostcondition = DeploymentReady.class), }) +@CSVMetadata(name = DebeziumCsvMetadata.NAME) public class DebeziumServerReconciler implements Reconciler { @Override diff --git a/src/main/java/io/debezium/operator/dependent/RoleBindingDependent.java b/src/main/java/io/debezium/operator/dependent/RoleBindingDependent.java index 03f4208..46cfc98 100644 --- a/src/main/java/io/debezium/operator/dependent/RoleBindingDependent.java +++ b/src/main/java/io/debezium/operator/dependent/RoleBindingDependent.java @@ -8,6 +8,7 @@ import io.debezium.operator.DebeziumServer; import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import io.fabric8.kubernetes.api.model.ServiceAccount; +import io.fabric8.kubernetes.api.model.rbac.Role; import io.fabric8.kubernetes.api.model.rbac.RoleBinding; import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder; import io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder; @@ -17,8 +18,7 @@ public class RoleBindingDependent extends CRUDKubernetesDependentResource { - public static final String ROLE_NAME = "config-view"; - public static final String BINDING_NAME = "%s-" + ROLE_NAME; + public static final String BINDING_NAME = "%s-role-binding"; public RoleBindingDependent() { super(RoleBinding.class); @@ -30,14 +30,18 @@ protected RoleBinding desired(DebeziumServer primary, Context co .map(r -> r.getMetadata().getName()) .orElseThrow(); + var role = context.getSecondaryResource(Role.class) + .map(r -> r.getMetadata().getName()) + .orElseThrow(); + return new RoleBindingBuilder() .withMetadata(new ObjectMetaBuilder() - .withName(BINDING_NAME.formatted(sa)) + .withName(BINDING_NAME.formatted(role)) .withNamespace(primary.getMetadata().getNamespace()) .build()) .withRoleRef(new RoleRefBuilder() - .withKind("ClusterRole") - .withName(ROLE_NAME) + .withKind("Role") + .withName(role) .build()) .withSubjects(new SubjectBuilder() .withKind("ServiceAccount") diff --git a/src/main/java/io/debezium/operator/dependent/RoleDependent.java b/src/main/java/io/debezium/operator/dependent/RoleDependent.java new file mode 100644 index 0000000..17d2300 --- /dev/null +++ b/src/main/java/io/debezium/operator/dependent/RoleDependent.java @@ -0,0 +1,38 @@ +/* + * Copyright Debezium Authors. + * + * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package io.debezium.operator.dependent; + +import io.debezium.operator.DebeziumServer; +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; +import io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder; +import io.fabric8.kubernetes.api.model.rbac.Role; +import io.fabric8.kubernetes.api.model.rbac.RoleBuilder; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource; + +public class RoleDependent + extends CRUDKubernetesDependentResource { + public static final String ROLE_NAME = "%s-config-view"; + + public RoleDependent() { + super(Role.class); + } + + @Override + protected Role desired(DebeziumServer primary, Context context) { + return new RoleBuilder() + .withMetadata(new ObjectMetaBuilder() + .withName(ROLE_NAME.formatted(primary.getMetadata().getName())) + .withNamespace(primary.getMetadata().getNamespace()) + .build()) + .withRules(new PolicyRuleBuilder() + .withApiGroups("") + .withResources("secrets", "configmaps") + .withVerbs("get", "list", "watch") + .build()) + .build(); + } +} diff --git a/src/main/java/io/debezium/operator/dependent/ServiceAccountDependent.java b/src/main/java/io/debezium/operator/dependent/ServiceAccountDependent.java index 5d018a3..c44ba9e 100644 --- a/src/main/java/io/debezium/operator/dependent/ServiceAccountDependent.java +++ b/src/main/java/io/debezium/operator/dependent/ServiceAccountDependent.java @@ -15,7 +15,7 @@ public class ServiceAccountDependent extends CRUDKubernetesDependentResource { - public static final String SA_NAME = "%s-debezium-server"; + public static final String SA_NAME = "%s-sa"; public ServiceAccountDependent() { super(ServiceAccount.class); diff --git a/src/main/kubernetes/debezium-icon.svg b/src/main/kubernetes/debezium-icon.svg new file mode 100644 index 0000000..aea8428 --- /dev/null +++ b/src/main/kubernetes/debezium-icon.svg @@ -0,0 +1 @@ +color \ No newline at end of file From 45aa094fb1cf76652ec59ff7813fe4b561eefc86 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 18 Sep 2023 15:57:15 +0200 Subject: [PATCH 2/6] DBZ-6738 OLM support scripts --- .gitignore | 5 +- scripts/create-olm-bundle-images.sh | 85 +++++++++++++++ scripts/create-olm-test-catalog.sh | 149 +++++++++++++++++++++++++++ scripts/create-olm-test-resources.sh | 79 ++++++++++++++ scripts/functions.sh | 38 +++++++ 5 files changed, 355 insertions(+), 1 deletion(-) create mode 100755 scripts/create-olm-bundle-images.sh create mode 100755 scripts/create-olm-test-catalog.sh create mode 100755 scripts/create-olm-test-resources.sh create mode 100644 scripts/functions.sh diff --git a/.gitignore b/.gitignore index bf781c7..b216644 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 + +# OLM build workspace +olm/ \ No newline at end of file diff --git a/scripts/create-olm-bundle-images.sh b/scripts/create-olm-bundle-images.sh new file mode 100755 index 0000000..8246208 --- /dev/null +++ b/scripts/create-olm-bundle-images.sh @@ -0,0 +1,85 @@ +#! /usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/functions.sh" +checkDependencies + +OPTS=`getopt -o v:i: --long version:,input:,bundle-image:,push -n 'parse-options' -- "$@"` +if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi +eval set -- "$OPTS" + +# Set defaults +VERSION="all" +BUNDLE_IMAGE_PULL_URL="quay.io/debezium/operator-bundle" +INPUT_DIR_BASE="$PWD/olm/bundles" +PUSH_IMAGES=false + +# Process script options +while true; do + case "$1" in + -v | --version ) VERSION=$2; shift; shift ;; + -i | --input ) INPUT_DIR_BASE=$2; shift; shift ;; + --bundle-image ) BUNDLE_IMAGE_PULL_URL=$2; shift; shift ;; + --push ) PUSH_IMAGES=true; shift ;; + -- ) shift; break ;; + * ) break ;; + esac +done + +function validate_bundle() { + path=$1 + name=$2 + operator-sdk bundle validate "$path" + if [ $? != 0 ]; then + echo "OLM bundle '$name' is not valid." >&2 + exit 1 + fi +} + +function build_image() { + path=$1 + image=$2 + docker build -t "$image" -f "$path/bundle.Dockerfile" "$path" + if [[ "$PUSH_IMAGES" = true ]]; then + docker push "$image" + fi +} + +if [[ ! -d "$INPUT_DIR_BASE" ]]; then + echo "Input directory $INPUT_DIR_BASE not exists!" + exit 1 +fi + +echo "" +echo "Creating OLM bundle image(s)" +echo "Input dir: $INPUT_DIR_BASE" +echo "Bundle version(s): $VERSION" +echo "" + +if [[ $VERSION = "all" ]]; then + BUNDLES=( $INPUT_DIR_BASE/*/ ) +else + BUNDLES=( "$INPUT_DIR_BASE/$VERSION" ) +fi + + +for bundle in "${BUNDLES[@]}"; do + name="$(csvName $bundle)" + version="$(csvVersion $bundle)" + path="$(echo "${bundle%/}")" + image="$BUNDLE_IMAGE_PULL_URL:$version" + + echo "" + echo "Building image for bundle '$name'" + echo "Input dir: $path" + echo "Bundle image: $image" + echo "" + + validate_bundle $path $name + build_image $path $image + + echo "" + echo "Bundle image for '$name' build successfully!" +done; + diff --git a/scripts/create-olm-test-catalog.sh b/scripts/create-olm-test-catalog.sh new file mode 100755 index 0000000..9e3657b --- /dev/null +++ b/scripts/create-olm-test-catalog.sh @@ -0,0 +1,149 @@ +#! /usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/functions.sh" +checkDependencies + +OPTS=`getopt -o b:i:o:n:c:v:f --long bundle:,input:,output:,name:,channel:,version:,catalog-image:,bundle-image:,force,push -n 'parse-options' -- "$@"` +if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi +eval set -- "$OPTS" + +# Set defaults +BUNDLE_VERSION="all" +BUNDLE_IMAGE_PULL_URL="quay.io/debezium/operator-bundle" +CATALOG_VERSION="latest" +CATALOG_IMAGE_PULL_URL="quay.io/debezium/operator-catalog" +INPUT_DIR_BASE="$PWD/olm/bundles" +OUTPUT_DIR_BASE="$PWD/olm/catalog" +CATALOG_NAME="debezium-operator" +CATALOG_CHANNEL="alpha" +PUSH_IMAGE=false +FORCE=false + +# Process script options +while true; do + case "$1" in + -n | --name ) CATALOG_NAME=$2; shift; shift ;; + -b | --bundle ) BUNDLE_VERSION=$2; shift; shift ;; + -i | --input ) INPUT_DIR_BASE=$2; shift; shift ;; + -o | --output ) OUTPUT_DIR_BASE=$2; shift; shift ;; + -c | --channel ) CATALOG_CHANNEL=$2; shift; shift ;; + -v | --version ) CATALOG_VERSION=$2; shift; shift ;; + -f | --force ) FORCE=true; shift ;; + --push ) PUSH_IMAGE=true; shift ;; + --catalog-image ) CATALOG_IMAGE=$2; shift; shift ;; + --bundle-image ) BUNDLE_IMAGE_PULL_URL=$2; shift; shift ;; + -- ) shift; break ;; + * ) break ;; + esac +done + +if [[ ! -d "$INPUT_DIR_BASE" ]]; then + echo "Input directory $INPUT_DIR_BASE not exists!" + exit 1 +fi + +# Set variables +CATALOG_DIR="$OUTPUT_DIR_BASE/$CATALOG_NAME" +CATALOG_MANIFEST_FILE="$CATALOG_DIR/operator.yaml" +CATALOG_DOCKER_FILE="$OUTPUT_DIR_BASE/$CATALOG_NAME.Dockerfile" +CATALOG_IMAGE="$CATALOG_IMAGE_PULL_URL:$CATALOG_VERSION" + +echo "" +echo "Creating OLM catalog" +echo "Bundle input dir: $INPUT_DIR_BASE" +echo "Bundle bundle(s): $BUNDLE_VERSION" +echo "" + +if [[ $BUNDLE_VERSION = "all" ]]; then + BUNDLES=( $INPUT_DIR_BASE/*/ ) +else + BUNDLES=( "$INPUT_DIR_BASE/$BUNDLE_VERSION" ) +fi + +if [[ -d "$CATALOG_DIR" && "$FORCE" = true ]]; then + echo "Removing exiting catalog directory '$CATALOG_DIR'" + rm -rf "$CATALOG_DIR" +fi + +if [[ -f "$CATALOG_DOCKER_FILE" && "$FORCE" = true ]]; then + echo "Removing exiting catalog dockerfile '$CATALOG_DOCKER_FILE'" + rm -rf "$CATALOG_DOCKER_FILE" +fi + +if [[ -d "$CATALOG_DIR" ]]; then + echo "Directory $CATALOG_DIR already exists!" + echo "Use -f / --force to overwrite" + exit 2 +fi + +if [[ -d "$CATALOG_DOCKER_FILE" ]]; then + echo "Dockerfile $CATALOG_DOCKER_FILE already exists!" + echo "Use -f / --force to overwrite" + exit 3 +fi + +# Generate dockerfile and initialize catalog manifest +mkdir -p "$CATALOG_DIR" +opm generate dockerfile "$CATALOG_DIR" +opm init "$CATALOG_NAME" --default-channel="$CATALOG_CHANNEL" --output yaml > "$CATALOG_MANIFEST_FILE" + +# Render each bundle +for bundle in "${BUNDLES[@]}"; do + name="$(csvName $bundle)" + version="$(csvVersion $bundle)" + image="$BUNDLE_IMAGE_PULL_URL:$version" + + echo "" + echo "Rendering bundle '$name'" + echo "Bundle directory: " $bundle + echo "Bundle image: $image " + echo "" + + opm render "$image" --output=yaml >> "$CATALOG_MANIFEST_FILE" +done; + + +# Write out channel declaration +echo "" +echo "Creating channel '$name'" +echo "" +cat << EOF >> "$CATALOG_MANIFEST_FILE" +--- +schema: olm.channel +package: $CATALOG_NAME +name: $CATALOG_CHANNEL +entries: +EOF + +# Write out channel entries +for bundle in "${BUNDLES[@]}"; do + name="$(csvName $bundle)" + replaces="$(csvReplaces $bundle)" + + echo " - name: $name" >> "$CATALOG_MANIFEST_FILE" + [ $replaces != "null" ] && echo " replaces: $replaces" >> "$CATALOG_MANIFEST_FILE" +done; + + +# Validate generated catalog +opm validate "$CATALOG_DIR" + +# Build image +docker build -t "$CATALOG_IMAGE" -f "$CATALOG_DOCKER_FILE" "$OUTPUT_DIR_BASE" + +echo "" +echo "Catalog created!" +echo "Output dir: $OUTPUT_DIR_BASE" +echo "Name: $CATALOG_NAME" +echo "Channel: $CATALOG_CHANNEL" +echo "Image: $CATALOG_IMAGE" +echo "" + + +if [[ "$PUSH_IMAGE" = true ]]; then + echo "" + echo "Pushing image: $CATALOG_IMAGE" + docker push "$CATALOG_IMAGE" +fi diff --git a/scripts/create-olm-test-resources.sh b/scripts/create-olm-test-resources.sh new file mode 100755 index 0000000..55572d8 --- /dev/null +++ b/scripts/create-olm-test-resources.sh @@ -0,0 +1,79 @@ +#! /usr/bin/env bash +set -euo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +source "$SCRIPT_DIR/functions.sh" +checkDependencies + +OPTS=`getopt -o b:o:n:c:v: --long bundle:,output:,namespace:,channel:,version:,catalog-image: -n 'parse-options' -- "$@"` +if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi +eval set -- "$OPTS" + +# Set defaults +CATALOG_VERSION="latest" +CATALOG_IMAGE="quay.io/debezium/operator-catalog:latest" +OUTPUT_DIR_BASE="$PWD/olm/test-resources" +CATALOG_NAME="debezium-operator-catalog" +CATALOG_NAMESPACE="olm" +SUBSCRIPTION_CHANNEL="alpha" +SUBSCRIPTION_NS="operators" + +# Process script options +while true; do + case "$1" in + -n | --namespace ) SUBSCRIPTION_NS=$2; shift; shift ;; + -b | --bundle ) BUNDLE=$2; shift; shift ;; + -o | --output ) OUTPUT_DIR_BASE=$2; shift; shift ;; + -c | --channel ) SUBSCRIPTION_CHANNEL=$2; shift; shift ;; + -v | --version ) CATALOG_VERSION=$2; shift; shift ;; + --watch-namespace ) WATCH_NS=$2; shift; shift ;; + --catalog-image ) CATALOG_IMAGE=$2; shift; shift ;; + --catalog-ns ) CATALOG_NAMESPACE=$2; shift; shift ;; + -- ) shift; break ;; + * ) break ;; + esac +done + +rm -rf "$OUTPUT_DIR_BASE" +mkdir -p "$OUTPUT_DIR_BASE" + + +echo "" +echo "Creating OLM test resources" +echo "Output dir: $OUTPUT_DIR_BASE" +echo "" + +cat << EOF >> "$OUTPUT_DIR_BASE/catalog.yaml" +apiVersion: operators.coreos.com/v1alpha1 +kind: CatalogSource +metadata: + name: $CATALOG_NAME + namespace: $CATALOG_NAMESPACE +spec: + grpcPodConfig: + securityContextConfig: restricted + sourceType: grpc + image: $CATALOG_IMAGE + displayName: Debezium Test Catalog + publisher: Me + updateStrategy: + registryPoll: + interval: 10m +EOF + +cat << EOF >> "$OUTPUT_DIR_BASE/subscription.yaml" +apiVersion: operators.coreos.com/v1alpha1 +kind: Subscription +metadata: + name: debezium-operator-subscription + namespace: $SUBSCRIPTION_NS +spec: + installPlanApproval: Automatic + name: debezium-operator + source: $CATALOG_NAME + sourceNamespace: $CATALOG_NAMESPACE + startingCSV: $BUNDLE +EOF + + + diff --git a/scripts/functions.sh b/scripts/functions.sh new file mode 100644 index 0000000..df6ac0c --- /dev/null +++ b/scripts/functions.sh @@ -0,0 +1,38 @@ +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) +} + +function requireGnuGetopt() { + getopt_version="$(getopt --version)" + if ! [[ "$getopt_version" =~ .*"getopt from util-linux".* ]]; then + echo "GNU getopt is required" + echo "On MacOS it can be installed by running 'brew install gnu-getopt'" + exit 256 + fi +} + +function requireYq() { + if ! command -v yq &> /dev/null + then + echo "Missing yq!" + echo "https://github.com/mikefarah/yq#install" + exit 256 + fi +} + +function checkDependencies() { + requireGnuGetopt + requireYq +} \ No newline at end of file From 598e71c13de5ba261a4540bec20f294376e1d340 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 18 Sep 2023 16:27:38 +0200 Subject: [PATCH 3/6] DBZ-6738 POM cleanup --- pom.xml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 4ccaace..d432987 100644 --- a/pom.xml +++ b/pom.xml @@ -20,22 +20,27 @@ + UTF-8 + UTF-8 + 17 + 17 + ${project.version} - ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x - 3.11.0 - 17 - 17 - UTF-8 - UTF-8 + + 3.4.0 + 3.0.0 + 3.11.0 + + + 3.24.2 + + quarkus-bom io.quarkus 3.2.4.Final 6.3.0 - true - 3.0.0 - 3.24.2 false @@ -45,6 +50,8 @@ operator nightly debezium-operator + + ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x 17 @@ -123,7 +130,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.4.0 + ${version.buildhelper.plugin} initialize @@ -151,7 +158,7 @@ maven-compiler-plugin - ${compiler-plugin.version} + ${version.compiler.plugin} -parameters @@ -160,7 +167,7 @@ maven-surefire-plugin - ${surefire-plugin.version} + ${version.surefire.plugin} org.jboss.logmanager.LogManager @@ -170,7 +177,7 @@ maven-failsafe-plugin - ${surefire-plugin.version} + ${version.surefire.plugin} From ce958eb12862e130b22eba0562462f5498839f25 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 18 Sep 2023 19:04:38 +0200 Subject: [PATCH 4/6] DBZ-6738 Functional bundle can be generated during maven build This uses combination of maven resources plugin to perform property filtering and Fabric8 docker plugin to wire OLM and QOSDK configuration together. --- .gitignore | 3 +- olm/bundles/README.md | 8 ++ pom.xml | 92 ++++++++++++++++++- .../operator/DebeziumCsvMetadata.java | 2 +- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 olm/bundles/README.md diff --git a/.gitignore b/.gitignore index b216644..fa0c1be 100644 --- a/.gitignore +++ b/.gitignore @@ -46,4 +46,5 @@ nb-configuration.xml kubernetes.json # OLM build workspace -olm/ \ No newline at end of file +olm/* +!olm/bundles \ No newline at end of file diff --git a/olm/bundles/README.md b/olm/bundles/README.md new file mode 100644 index 0000000..8174be5 --- /dev/null +++ b/olm/bundles/README.md @@ -0,0 +1,8 @@ +# Debezium Operator OLM Bundle Manifests +For main branch this directory is expected to be empty. For release branches the raw OLM bundle manifests should be located here. + +_Note that such OLM bundle requires further processing and without it the bundle is not usable._ + +To release this bundle follow the instruction is [Operator Bundle Manifests repository](https://github.com/debezium/debezium-operator-manifests). + + diff --git a/pom.xml b/pom.xml index d432987..5a35649 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ UTF-8 17 17 + yyyy-MM-dd'T'HH:mm:ss'Z' ${project.version} @@ -32,6 +33,9 @@ 3.4.0 3.0.0 3.11.0 + 3.3.1 + 0.43.4 + 3.24.2 @@ -44,7 +48,6 @@ false - ${project.artifactId} quay.io debezium operator @@ -52,6 +55,11 @@ debezium-operator ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x + ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-nightly + debezium-operator.v${olm.bundle.version} + + ${quarkus.container-image.registry}/${quarkus.container-image.group}/${quarkus.container-image.name}:${quarkus.container-image.tag} + ${maven.build.timestamp} 17 @@ -216,6 +224,7 @@ ${project.parent.version} debezium-${version.debezium.channel} + ${project.parent.version} @@ -226,6 +235,87 @@ debezium-stable,debezium-${version.debezium.channel} + + olmUpdate + + true + + $$ + + + + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + copy-olm + package + + copy-resources + + + ${project.basedir}/olm/bundles/${olm.bundle.version} + + + + ${project.build.directory}/bundle/${dollar}{olm.bundle.name} + **/* + true + + + true + + + + + + + + + + + io.fabric8 + docker-maven-plugin + ${version.docker.maven.plugin} + + + + yq + mikefarah/yq:latest + + true + + + ${project.basedir}/olm/bundles/${olm.bundle.version}:/workdir + + + + + 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']"}}}] + manifests/${olm.bundle.name}.clusterserviceversion.yaml + + + + + + + + + wire-olm + package + + start + + + + + + + k8update diff --git a/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java index 4a61a51..5c2a128 100644 --- a/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java +++ b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java @@ -89,5 +89,5 @@ "Start it up, point it at your databases, and your apps can start responding " + "to all of the inserts, updates, and deletes that other apps commit to your databases") public class DebeziumCsvMetadata implements SharedCSVMetadata { - public static final String NAME = "debezium-operator"; + public static final String NAME = "${olm.bundle.name}"; } From 2670fc1b1a0e5ac8c3c48a0e5d7405591c8bfe31 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 25 Sep 2023 12:28:37 +0200 Subject: [PATCH 5/6] DBZ-6738 Adjusting for the latest QOSDK release and fixes comming with it --- .gitignore | 6 +- k8/kubernetes.yml | 4 - olm/bundles/README.md | 8 - pom.xml | 171 +++++++----------- src/main/assemblies/olm.xml | 33 ++++ .../assembly.xml => assemblies/operator.xml} | 0 .../operator/DebeziumCsvMetadata.java | 17 +- .../operator/DebeziumServerReconciler.java | 2 +- 8 files changed, 112 insertions(+), 129 deletions(-) delete mode 100644 olm/bundles/README.md create mode 100644 src/main/assemblies/olm.xml rename src/main/{resources/assembly.xml => assemblies/operator.xml} (100%) diff --git a/.gitignore b/.gitignore index fa0c1be..bf781c7 100644 --- a/.gitignore +++ b/.gitignore @@ -43,8 +43,4 @@ nb-configuration.xml /.quarkus/cli/plugins/ # kubernetes -kubernetes.json - -# OLM build workspace -olm/* -!olm/bundles \ No newline at end of file +kubernetes.json \ No newline at end of file diff --git a/k8/kubernetes.yml b/k8/kubernetes.yml index 5336f0e..171c7a9 100644 --- a/k8/kubernetes.yml +++ b/k8/kubernetes.yml @@ -151,10 +151,6 @@ spec: port: 80 protocol: TCP targetPort: 8080 - - name: https - port: 443 - protocol: TCP - targetPort: 8443 selector: app.kubernetes.io/name: debezium-operator type: ClusterIP diff --git a/olm/bundles/README.md b/olm/bundles/README.md deleted file mode 100644 index 8174be5..0000000 --- a/olm/bundles/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Debezium Operator OLM Bundle Manifests -For main branch this directory is expected to be empty. For release branches the raw OLM bundle manifests should be located here. - -_Note that such OLM bundle requires further processing and without it the bundle is not usable._ - -To release this bundle follow the instruction is [Operator Bundle Manifests repository](https://github.com/debezium/debezium-operator-manifests). - - diff --git a/pom.xml b/pom.xml index 5a35649..ad3b028 100644 --- a/pom.xml +++ b/pom.xml @@ -36,34 +36,42 @@ 3.3.1 0.43.4 - 3.24.2 + + debezium-operator.v${olm.bundle.version} + alpha + ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-nightly + + ${quarkus.container-image.registry}/${quarkus.container-image.group}/${quarkus.container-image.name}:${quarkus.container-image.tag} + ${maven.build.timestamp} + debezium-operator + quarkus-bom io.quarkus 3.2.4.Final - 6.3.0 + 6.3.3 false + ${olm.bundle.version} + ${olm.bundle.replaces} + ${olm.bundle.package.name} quay.io debezium operator nightly debezium-operator - - ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x - ${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-nightly - debezium-operator.v${olm.bundle.version} - - ${quarkus.container-image.registry}/${quarkus.container-image.group}/${quarkus.container-image.name}:${quarkus.container-image.tag} - ${maven.build.timestamp} + true + 17 ${quarkus.container-image.tag} + + $$ @@ -203,6 +211,32 @@ + + org.apache.maven.plugins + maven-resources-plugin + ${version.resources.plugin} + + + olm-bundle-process + package + + copy-resources + + + ${project.build.directory}/olm/bundles/${olm.bundle.name} + + + + ${project.build.directory}/bundle/${dollar}{olm.bundle.name} + **/* + true + + + true + + + + @@ -223,104 +257,22 @@ stable ${project.parent.version} - debezium-${version.debezium.channel} + ${olm.bundle.channels} ${project.parent.version} + debezium-${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x - olmStable + + olmLatest - debezium-stable,debezium-${version.debezium.channel} + debezium-latest,${olm.bundle.channels} - - olmUpdate - - true - - $$ - - - - - org.apache.maven.plugins - maven-resources-plugin - ${version.resources.plugin} - - - copy-olm - package - - copy-resources - - - ${project.basedir}/olm/bundles/${olm.bundle.version} - - - - ${project.build.directory}/bundle/${dollar}{olm.bundle.name} - **/* - true - - - true - - - - - - - - - - - io.fabric8 - docker-maven-plugin - ${version.docker.maven.plugin} - - - - yq - mikefarah/yq:latest - - true - - - ${project.basedir}/olm/bundles/${olm.bundle.version}:/workdir - - - - - 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']"}}}] - manifests/${olm.bundle.name}.clusterserviceversion.yaml - - - - - - - - - wire-olm - package - - start - - - - - - - k8update - - true - @@ -375,20 +327,35 @@ maven-assembly-plugin ${version.assembly.plugin} - false - true - - src/main/resources/assembly.xml - + true posix - distribution + operator-package package single + + false + + src/main/assemblies/operator.xml + + + + + olm-bundle-package + package + + single + + + true + + src/main/assemblies/olm.xml + + diff --git a/src/main/assemblies/olm.xml b/src/main/assemblies/olm.xml new file mode 100644 index 0000000..8710302 --- /dev/null +++ b/src/main/assemblies/olm.xml @@ -0,0 +1,33 @@ + + olm-bundle + + tar.gz + zip + + + false + + + + ${project.basedir}. + + + README* + CHANGELOG* + CONTRIBUTE* + COPYRIGHT* + LICENSE* + + true + + + ${project.build.directory}/olm/bundles/ + . + + **/** + + + + \ No newline at end of file diff --git a/src/main/resources/assembly.xml b/src/main/assemblies/operator.xml similarity index 100% rename from src/main/resources/assembly.xml rename to src/main/assemblies/operator.xml diff --git a/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java index 5c2a128..9d81bf3 100644 --- a/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java +++ b/src/main/java/io/debezium/operator/DebeziumCsvMetadata.java @@ -5,20 +5,19 @@ */ package io.debezium.operator; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Annotations; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Icon; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.InstallMode; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Link; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Maintainer; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata.Provider; -import io.quarkiverse.operatorsdk.bundle.runtime.SharedCSVMetadata; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.Annotations; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.Icon; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.InstallMode; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.Link; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.Maintainer; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata.Provider; +import io.quarkiverse.operatorsdk.annotations.SharedCSVMetadata; // @formatter:off @CSVMetadata( name = DebeziumCsvMetadata.NAME, displayName = "Debezium Operator", - version = "${olm.bundle.version}", replaces = "${olm.bundle.replaces}", icon = @Icon(fileName = "debezium-icon.svg"), provider = @Provider(name = "Debezium Authors", url = "https://debezium.io/"), maintainers = @Maintainer(name = "Debezium Authors", email = "debezium@googlegroups.com"), diff --git a/src/main/java/io/debezium/operator/DebeziumServerReconciler.java b/src/main/java/io/debezium/operator/DebeziumServerReconciler.java index 7374cd7..4743c49 100644 --- a/src/main/java/io/debezium/operator/DebeziumServerReconciler.java +++ b/src/main/java/io/debezium/operator/DebeziumServerReconciler.java @@ -23,7 +23,7 @@ import io.javaoperatorsdk.operator.api.reconciler.Reconciler; import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent; -import io.quarkiverse.operatorsdk.bundle.runtime.CSVMetadata; +import io.quarkiverse.operatorsdk.annotations.CSVMetadata; import io.quarkus.logging.Log; @ControllerConfiguration(namespaces = Constants.WATCH_CURRENT_NAMESPACE, name = "debeziumserver", dependents = { From 821b2392af17d5749f2cd3fd5280347a53b46f56 Mon Sep 17 00:00:00 2001 From: Jakub Cechacek Date: Mon, 25 Sep 2023 13:44:56 +0200 Subject: [PATCH 6/6] DBZ-6738 Moving olm support scripts to manifest repo --- scripts/create-olm-bundle-images.sh | 85 --------------- scripts/create-olm-test-catalog.sh | 149 --------------------------- scripts/create-olm-test-resources.sh | 79 -------------- scripts/functions.sh | 38 ------- 4 files changed, 351 deletions(-) delete mode 100755 scripts/create-olm-bundle-images.sh delete mode 100755 scripts/create-olm-test-catalog.sh delete mode 100755 scripts/create-olm-test-resources.sh delete mode 100644 scripts/functions.sh diff --git a/scripts/create-olm-bundle-images.sh b/scripts/create-olm-bundle-images.sh deleted file mode 100755 index 8246208..0000000 --- a/scripts/create-olm-bundle-images.sh +++ /dev/null @@ -1,85 +0,0 @@ -#! /usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/functions.sh" -checkDependencies - -OPTS=`getopt -o v:i: --long version:,input:,bundle-image:,push -n 'parse-options' -- "$@"` -if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi -eval set -- "$OPTS" - -# Set defaults -VERSION="all" -BUNDLE_IMAGE_PULL_URL="quay.io/debezium/operator-bundle" -INPUT_DIR_BASE="$PWD/olm/bundles" -PUSH_IMAGES=false - -# Process script options -while true; do - case "$1" in - -v | --version ) VERSION=$2; shift; shift ;; - -i | --input ) INPUT_DIR_BASE=$2; shift; shift ;; - --bundle-image ) BUNDLE_IMAGE_PULL_URL=$2; shift; shift ;; - --push ) PUSH_IMAGES=true; shift ;; - -- ) shift; break ;; - * ) break ;; - esac -done - -function validate_bundle() { - path=$1 - name=$2 - operator-sdk bundle validate "$path" - if [ $? != 0 ]; then - echo "OLM bundle '$name' is not valid." >&2 - exit 1 - fi -} - -function build_image() { - path=$1 - image=$2 - docker build -t "$image" -f "$path/bundle.Dockerfile" "$path" - if [[ "$PUSH_IMAGES" = true ]]; then - docker push "$image" - fi -} - -if [[ ! -d "$INPUT_DIR_BASE" ]]; then - echo "Input directory $INPUT_DIR_BASE not exists!" - exit 1 -fi - -echo "" -echo "Creating OLM bundle image(s)" -echo "Input dir: $INPUT_DIR_BASE" -echo "Bundle version(s): $VERSION" -echo "" - -if [[ $VERSION = "all" ]]; then - BUNDLES=( $INPUT_DIR_BASE/*/ ) -else - BUNDLES=( "$INPUT_DIR_BASE/$VERSION" ) -fi - - -for bundle in "${BUNDLES[@]}"; do - name="$(csvName $bundle)" - version="$(csvVersion $bundle)" - path="$(echo "${bundle%/}")" - image="$BUNDLE_IMAGE_PULL_URL:$version" - - echo "" - echo "Building image for bundle '$name'" - echo "Input dir: $path" - echo "Bundle image: $image" - echo "" - - validate_bundle $path $name - build_image $path $image - - echo "" - echo "Bundle image for '$name' build successfully!" -done; - diff --git a/scripts/create-olm-test-catalog.sh b/scripts/create-olm-test-catalog.sh deleted file mode 100755 index 9e3657b..0000000 --- a/scripts/create-olm-test-catalog.sh +++ /dev/null @@ -1,149 +0,0 @@ -#! /usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/functions.sh" -checkDependencies - -OPTS=`getopt -o b:i:o:n:c:v:f --long bundle:,input:,output:,name:,channel:,version:,catalog-image:,bundle-image:,force,push -n 'parse-options' -- "$@"` -if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi -eval set -- "$OPTS" - -# Set defaults -BUNDLE_VERSION="all" -BUNDLE_IMAGE_PULL_URL="quay.io/debezium/operator-bundle" -CATALOG_VERSION="latest" -CATALOG_IMAGE_PULL_URL="quay.io/debezium/operator-catalog" -INPUT_DIR_BASE="$PWD/olm/bundles" -OUTPUT_DIR_BASE="$PWD/olm/catalog" -CATALOG_NAME="debezium-operator" -CATALOG_CHANNEL="alpha" -PUSH_IMAGE=false -FORCE=false - -# Process script options -while true; do - case "$1" in - -n | --name ) CATALOG_NAME=$2; shift; shift ;; - -b | --bundle ) BUNDLE_VERSION=$2; shift; shift ;; - -i | --input ) INPUT_DIR_BASE=$2; shift; shift ;; - -o | --output ) OUTPUT_DIR_BASE=$2; shift; shift ;; - -c | --channel ) CATALOG_CHANNEL=$2; shift; shift ;; - -v | --version ) CATALOG_VERSION=$2; shift; shift ;; - -f | --force ) FORCE=true; shift ;; - --push ) PUSH_IMAGE=true; shift ;; - --catalog-image ) CATALOG_IMAGE=$2; shift; shift ;; - --bundle-image ) BUNDLE_IMAGE_PULL_URL=$2; shift; shift ;; - -- ) shift; break ;; - * ) break ;; - esac -done - -if [[ ! -d "$INPUT_DIR_BASE" ]]; then - echo "Input directory $INPUT_DIR_BASE not exists!" - exit 1 -fi - -# Set variables -CATALOG_DIR="$OUTPUT_DIR_BASE/$CATALOG_NAME" -CATALOG_MANIFEST_FILE="$CATALOG_DIR/operator.yaml" -CATALOG_DOCKER_FILE="$OUTPUT_DIR_BASE/$CATALOG_NAME.Dockerfile" -CATALOG_IMAGE="$CATALOG_IMAGE_PULL_URL:$CATALOG_VERSION" - -echo "" -echo "Creating OLM catalog" -echo "Bundle input dir: $INPUT_DIR_BASE" -echo "Bundle bundle(s): $BUNDLE_VERSION" -echo "" - -if [[ $BUNDLE_VERSION = "all" ]]; then - BUNDLES=( $INPUT_DIR_BASE/*/ ) -else - BUNDLES=( "$INPUT_DIR_BASE/$BUNDLE_VERSION" ) -fi - -if [[ -d "$CATALOG_DIR" && "$FORCE" = true ]]; then - echo "Removing exiting catalog directory '$CATALOG_DIR'" - rm -rf "$CATALOG_DIR" -fi - -if [[ -f "$CATALOG_DOCKER_FILE" && "$FORCE" = true ]]; then - echo "Removing exiting catalog dockerfile '$CATALOG_DOCKER_FILE'" - rm -rf "$CATALOG_DOCKER_FILE" -fi - -if [[ -d "$CATALOG_DIR" ]]; then - echo "Directory $CATALOG_DIR already exists!" - echo "Use -f / --force to overwrite" - exit 2 -fi - -if [[ -d "$CATALOG_DOCKER_FILE" ]]; then - echo "Dockerfile $CATALOG_DOCKER_FILE already exists!" - echo "Use -f / --force to overwrite" - exit 3 -fi - -# Generate dockerfile and initialize catalog manifest -mkdir -p "$CATALOG_DIR" -opm generate dockerfile "$CATALOG_DIR" -opm init "$CATALOG_NAME" --default-channel="$CATALOG_CHANNEL" --output yaml > "$CATALOG_MANIFEST_FILE" - -# Render each bundle -for bundle in "${BUNDLES[@]}"; do - name="$(csvName $bundle)" - version="$(csvVersion $bundle)" - image="$BUNDLE_IMAGE_PULL_URL:$version" - - echo "" - echo "Rendering bundle '$name'" - echo "Bundle directory: " $bundle - echo "Bundle image: $image " - echo "" - - opm render "$image" --output=yaml >> "$CATALOG_MANIFEST_FILE" -done; - - -# Write out channel declaration -echo "" -echo "Creating channel '$name'" -echo "" -cat << EOF >> "$CATALOG_MANIFEST_FILE" ---- -schema: olm.channel -package: $CATALOG_NAME -name: $CATALOG_CHANNEL -entries: -EOF - -# Write out channel entries -for bundle in "${BUNDLES[@]}"; do - name="$(csvName $bundle)" - replaces="$(csvReplaces $bundle)" - - echo " - name: $name" >> "$CATALOG_MANIFEST_FILE" - [ $replaces != "null" ] && echo " replaces: $replaces" >> "$CATALOG_MANIFEST_FILE" -done; - - -# Validate generated catalog -opm validate "$CATALOG_DIR" - -# Build image -docker build -t "$CATALOG_IMAGE" -f "$CATALOG_DOCKER_FILE" "$OUTPUT_DIR_BASE" - -echo "" -echo "Catalog created!" -echo "Output dir: $OUTPUT_DIR_BASE" -echo "Name: $CATALOG_NAME" -echo "Channel: $CATALOG_CHANNEL" -echo "Image: $CATALOG_IMAGE" -echo "" - - -if [[ "$PUSH_IMAGE" = true ]]; then - echo "" - echo "Pushing image: $CATALOG_IMAGE" - docker push "$CATALOG_IMAGE" -fi diff --git a/scripts/create-olm-test-resources.sh b/scripts/create-olm-test-resources.sh deleted file mode 100755 index 55572d8..0000000 --- a/scripts/create-olm-test-resources.sh +++ /dev/null @@ -1,79 +0,0 @@ -#! /usr/bin/env bash -set -euo pipefail - -SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -source "$SCRIPT_DIR/functions.sh" -checkDependencies - -OPTS=`getopt -o b:o:n:c:v: --long bundle:,output:,namespace:,channel:,version:,catalog-image: -n 'parse-options' -- "$@"` -if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi -eval set -- "$OPTS" - -# Set defaults -CATALOG_VERSION="latest" -CATALOG_IMAGE="quay.io/debezium/operator-catalog:latest" -OUTPUT_DIR_BASE="$PWD/olm/test-resources" -CATALOG_NAME="debezium-operator-catalog" -CATALOG_NAMESPACE="olm" -SUBSCRIPTION_CHANNEL="alpha" -SUBSCRIPTION_NS="operators" - -# Process script options -while true; do - case "$1" in - -n | --namespace ) SUBSCRIPTION_NS=$2; shift; shift ;; - -b | --bundle ) BUNDLE=$2; shift; shift ;; - -o | --output ) OUTPUT_DIR_BASE=$2; shift; shift ;; - -c | --channel ) SUBSCRIPTION_CHANNEL=$2; shift; shift ;; - -v | --version ) CATALOG_VERSION=$2; shift; shift ;; - --watch-namespace ) WATCH_NS=$2; shift; shift ;; - --catalog-image ) CATALOG_IMAGE=$2; shift; shift ;; - --catalog-ns ) CATALOG_NAMESPACE=$2; shift; shift ;; - -- ) shift; break ;; - * ) break ;; - esac -done - -rm -rf "$OUTPUT_DIR_BASE" -mkdir -p "$OUTPUT_DIR_BASE" - - -echo "" -echo "Creating OLM test resources" -echo "Output dir: $OUTPUT_DIR_BASE" -echo "" - -cat << EOF >> "$OUTPUT_DIR_BASE/catalog.yaml" -apiVersion: operators.coreos.com/v1alpha1 -kind: CatalogSource -metadata: - name: $CATALOG_NAME - namespace: $CATALOG_NAMESPACE -spec: - grpcPodConfig: - securityContextConfig: restricted - sourceType: grpc - image: $CATALOG_IMAGE - displayName: Debezium Test Catalog - publisher: Me - updateStrategy: - registryPoll: - interval: 10m -EOF - -cat << EOF >> "$OUTPUT_DIR_BASE/subscription.yaml" -apiVersion: operators.coreos.com/v1alpha1 -kind: Subscription -metadata: - name: debezium-operator-subscription - namespace: $SUBSCRIPTION_NS -spec: - installPlanApproval: Automatic - name: debezium-operator - source: $CATALOG_NAME - sourceNamespace: $CATALOG_NAMESPACE - startingCSV: $BUNDLE -EOF - - - diff --git a/scripts/functions.sh b/scripts/functions.sh deleted file mode 100644 index df6ac0c..0000000 --- a/scripts/functions.sh +++ /dev/null @@ -1,38 +0,0 @@ -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) -} - -function requireGnuGetopt() { - getopt_version="$(getopt --version)" - if ! [[ "$getopt_version" =~ .*"getopt from util-linux".* ]]; then - echo "GNU getopt is required" - echo "On MacOS it can be installed by running 'brew install gnu-getopt'" - exit 256 - fi -} - -function requireYq() { - if ! command -v yq &> /dev/null - then - echo "Missing yq!" - echo "https://github.com/mikefarah/yq#install" - exit 256 - fi -} - -function checkDependencies() { - requireGnuGetopt - requireYq -} \ No newline at end of file