Skip to content

Commit

Permalink
DBZ-6738 Suport for watching all namespaces with OLM installation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcechace committed Sep 18, 2023
1 parent 8d3f05f commit 1e1b285
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 27 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 18 additions & 13 deletions k8/kubernetes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,10 +49,10 @@ rules:
- get
- list
- watch
- create
- patch
- update
- delete
- create
- apiGroups:
- rbac.authorization.k8s.io
resources:
Expand All @@ -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:
Expand All @@ -73,10 +85,10 @@ rules:
- get
- list
- watch
- create
- patch
- update
- delete
- create
- apiGroups:
- apps
resources:
Expand All @@ -85,10 +97,10 @@ rules:
- get
- list
- watch
- create
- patch
- update
- delete
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Expand Down Expand Up @@ -135,10 +147,6 @@ metadata:
name: debezium-operator
spec:
ports:
- name: https
port: 443
protocol: TCP
targetPort: 8443
- name: http
port: 80
protocol: TCP
Expand All @@ -151,8 +159,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
Expand All @@ -162,8 +170,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:
Expand All @@ -188,9 +196,6 @@ spec:
- containerPort: 8080
name: http
protocol: TCP
- containerPort: 8443
name: https
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
Expand Down
31 changes: 27 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
<properties>
<!-- Debezium version -->
<version.debezium>${project.version}</version.debezium>
<version.debezium.channel>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.x</version.debezium.channel>

<compiler-plugin.version>3.11.0</compiler-plugin.version>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.testRelease>17</maven.compiler.testRelease>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.0.1.Final</quarkus.platform.version>
<quarkus.operator.sdk.version>6.1.0</quarkus.operator.sdk.version>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>3.2.4.Final</quarkus.platform.version>
<quarkus.operator.sdk.version>6.3.0</quarkus.operator.sdk.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.0.0</surefire-plugin.version>
<version.assertj>3.24.2</version.assertj>

<!-- Operator and Image configuration -->
<quarkus.operator-sdk.crd.validate>false</quarkus.operator-sdk.crd.validate>
<quarkus.operator-sdk.bundle.package-name>${project.artifactId}</quarkus.operator-sdk.bundle.package-name>
<quarkus.operator-sdk.bundle.channels>alpha</quarkus.operator-sdk.bundle.channels>
<quarkus.container-image.registry>quay.io</quarkus.container-image.registry>
<quarkus.container-image.group>debezium</quarkus.container-image.group>
<quarkus.container-image.name>operator</quarkus.container-image.name>
Expand Down Expand Up @@ -120,6 +120,20 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<phase>initialize</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
Expand Down Expand Up @@ -194,6 +208,15 @@
<id>stable</id>
<properties>
<quarkus.container-image.tag>${project.parent.version}</quarkus.container-image.tag>
<quarkus.operator-sdk.bundle.channels>debezium-${version.debezium.channel}</quarkus.operator-sdk.bundle.channels>
</properties>
</profile>
<profile>
<!-- This must be defined later than stable profile to ensure correct property resolution!!! -->
<!-- See: https://maven.apache.org/guides/introduction/introduction-to-profiles.html#profile-order -->
<id>olmStable</id>
<properties>
<quarkus.operator-sdk.bundle.channels>debezium-stable,debezium-${version.debezium.channel}</quarkus.operator-sdk.bundle.channels>
</properties>
</profile>
<profile>
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/io/debezium/operator/DebeziumCsvMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 = "debezium-operator",
displayName = "Debezium Operator",
version = "DBZOP_NEXT", replaces = "DBZOP_REPLACES",
icon = @Icon(fileName = "debezium-icon.svg"),
provider = @Provider(name = "Debezium Authors", url = "https://debezium.io/"),
maintainers = @Maintainer(name = "Debezium Authors", email = "[email protected]"),
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 = "DBZOP_IMAGE_PULL_URL:DBZOP_NEXT",
others = {
@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:[email protected]: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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +27,11 @@

@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,8 +18,7 @@

public class RoleBindingDependent
extends CRUDKubernetesDependentResource<RoleBinding, DebeziumServer> {
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);
Expand All @@ -30,14 +30,18 @@ protected RoleBinding desired(DebeziumServer primary, Context<DebeziumServer> 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")
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/io/debezium/operator/dependent/RoleDependent.java
Original file line number Diff line number Diff line change
@@ -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<Role, DebeziumServer> {
public static final String ROLE_NAME = "%s-config-view";

public RoleDependent() {
super(Role.class);
}

@Override
protected Role desired(DebeziumServer primary, Context<DebeziumServer> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class ServiceAccountDependent
extends CRUDKubernetesDependentResource<ServiceAccount, DebeziumServer> {

public static final String SA_NAME = "%s-debezium-server";
public static final String SA_NAME = "%s-sa";

public ServiceAccountDependent() {
super(ServiceAccount.class);
Expand Down
1 change: 1 addition & 0 deletions src/main/kubernetes/debezium-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1e1b285

Please sign in to comment.