Merge pull request #238 from halkyonio/quarkus-support · secondsun/java-operator-sdk@8a58f48 · GitHub
Skip to content

Commit 8a58f48

Browse files
authored
Merge pull request operator-framework#238 from halkyonio/quarkus-support
Extract controller configuration handling and provide Quarkus extension
2 parents 488d0ef + 06033fc commit 8a58f48

122 files changed

Lines changed: 1917 additions & 421 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 51 additions & 6 deletions

‎operator-framework-core/pom.xml‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.javaoperatorsdk</groupId>
8+
<artifactId>java-operator-sdk</artifactId>
9+
<version>1.5.1-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>operator-framework-core</artifactId>
14+
<name>Operator SDK - Framework - Core</name>
15+
<description>Core framework for implementing Kubernetes operators</description>
16+
<packaging>jar</packaging>
17+
18+
<properties>
19+
<java.version>11</java.version>
20+
<maven.compiler.source>11</maven.compiler.source>
21+
<maven.compiler.target>11</maven.compiler.target>
22+
</properties>
23+
24+
<build>
25+
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-surefire-plugin</artifactId>
29+
<version>${surefire.version}</version>
30+
</plugin>
31+
</plugins>
32+
</build>
33+
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>io.fabric8</groupId>
38+
<artifactId>openshift-client</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.slf4j</groupId>
42+
<artifactId>slf4j-api</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-api</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter-engine</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.mockito</groupId>
57+
<artifactId>mockito-core</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.apache.logging.log4j</groupId>
62+
<artifactId>log4j-slf4j-impl</artifactId>
63+
<version>2.13.3</version>
64+
<scope>test</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.assertj</groupId>
68+
<artifactId>assertj-core</artifactId>
69+
<version>3.18.0</version>
70+
<scope>test</scope>
71+
</dependency>
72+
</dependencies>
73+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.javaoperatorsdk.operator;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
import io.javaoperatorsdk.operator.api.ResourceController;
5+
import java.util.Locale;
6+
7+
public class ControllerUtils {
8+
9+
private static final String FINALIZER_NAME_SUFFIX = "/finalizer";
10+
11+
public static String getDefaultFinalizerName(String crdName) {
12+
return crdName + FINALIZER_NAME_SUFFIX;
13+
}
14+
15+
public static boolean hasGivenFinalizer(CustomResource resource, String finalizer) {
16+
return resource.getMetadata().getFinalizers() != null
17+
&& resource.getMetadata().getFinalizers().contains(finalizer);
18+
}
19+
20+
public static String getDefaultNameFor(ResourceController controller) {
21+
return getDefaultNameFor(controller.getClass());
22+
}
23+
24+
public static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) {
25+
return getDefaultResourceControllerName(controllerClass.getSimpleName());
26+
}
27+
28+
public static String getDefaultResourceControllerName(String rcControllerClassName) {
29+
final var lastDot = rcControllerClassName.lastIndexOf('.');
30+
if (lastDot > 0) {
31+
rcControllerClassName = rcControllerClassName.substring(lastDot);
32+
}
33+
return rcControllerClassName.toLowerCase(Locale.ROOT);
34+
}
35+
}

operator-framework/src/main/java/io/javaoperatorsdk/operator/EventListUtils.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/EventListUtils.java

File renamed without changes.

operator-framework/src/main/java/io/javaoperatorsdk/operator/Operator.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.javaoperatorsdk.operator;
22

3-
import static io.javaoperatorsdk.operator.ControllerUtils.getCrdName;
4-
import static io.javaoperatorsdk.operator.ControllerUtils.getCustomResourceClass;
5-
63
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
74
import io.fabric8.kubernetes.client.CustomResource;
85
import io.fabric8.kubernetes.client.CustomResourceDoneable;
@@ -13,11 +10,13 @@
1310
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl;
1411
import io.fabric8.kubernetes.internal.KubernetesDeserializer;
1512
import io.javaoperatorsdk.operator.api.ResourceController;
13+
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
1614
import io.javaoperatorsdk.operator.processing.CustomResourceCache;
1715
import io.javaoperatorsdk.operator.processing.DefaultEventHandler;
1816
import io.javaoperatorsdk.operator.processing.EventDispatcher;
1917
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
2018
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventSource;
19+
import io.javaoperatorsdk.operator.processing.retry.GenericRetry;
2120
import io.javaoperatorsdk.operator.processing.retry.Retry;
2221
import java.util.Arrays;
2322
import java.util.HashMap;
@@ -30,11 +29,21 @@ public class Operator {
3029

3130
private static final Logger log = LoggerFactory.getLogger(Operator.class);
3231
private final KubernetesClient k8sClient;
32+
private final ConfigurationService configurationService;
3333
private Map<Class<? extends CustomResource>, CustomResourceOperationsImpl> customResourceClients =
3434
new HashMap<>();
3535

36-
public Operator(KubernetesClient k8sClient) {
36+
public Operator(KubernetesClient k8sClient, ConfigurationService configurationService) {
3737
this.k8sClient = k8sClient;
38+
this.configurationService = configurationService;
39+
}
40+
41+
public <R extends CustomResource> void register(ResourceController<R> controller)
42+
throws OperatorException {
43+
final var configuration = configurationService.getConfigurationFor(controller);
44+
final var retry = GenericRetry.fromConfiguration(configuration.getRetryConfiguration());
45+
final var targetNamespaces = configuration.getNamespaces().toArray(new String[] {});
46+
registerController(controller, configuration.watchAllNamespaces(), retry, targetNamespaces);
3847
}
3948

4049
public <R extends CustomResource> void registerControllerForAllNamespaces(
@@ -65,16 +74,14 @@ private <R extends CustomResource> void registerController(
6574
Retry retry,
6675
String... targetNamespaces)
6776
throws OperatorException {
68-
Class<R> resClass = getCustomResourceClass(controller);
77+
final var configuration = configurationService.getConfigurationFor(controller);
78+
Class<R> resClass = configuration.getCustomResourceClass();
6979
CustomResourceDefinitionContext crd = getCustomResourceDefinitionForController(controller);
7080
KubernetesDeserializer.registerCustomKind(crd.getVersion(), crd.getKind(), resClass);
71-
String finalizer = ControllerUtils.getFinalizer(controller);
81+
String finalizer = configuration.getFinalizer();
7282
MixedOperation client =
7383
k8sClient.customResources(
74-
crd,
75-
resClass,
76-
CustomResourceList.class,
77-
ControllerUtils.getCustomResourceDoneableClass(controller));
84+
crd, resClass, CustomResourceList.class, configuration.getDoneableClass());
7885
EventDispatcher eventDispatcher =
7986
new EventDispatcher(
8087
controller, finalizer, new EventDispatcher.CustomResourceFacade(client));
@@ -98,7 +105,7 @@ private <R extends CustomResource> void registerController(
98105
watchAllNamespaces,
99106
targetNamespaces,
100107
defaultEventHandler,
101-
ControllerUtils.getGenerationEventProcessing(controller),
108+
configuration.isGenerationAware(),
102109
finalizer);
103110
eventSourceManager.registerCustomResourceEventSource(customResourceEventSource);
104111

@@ -133,7 +140,7 @@ private CustomResourceEventSource createCustomResourceEventSource(
133140

134141
private CustomResourceDefinitionContext getCustomResourceDefinitionForController(
135142
ResourceController controller) {
136-
String crdName = getCrdName(controller);
143+
final var crdName = configurationService.getConfigurationFor(controller).getCRDName();
137144
CustomResourceDefinition customResourceDefinition =
138145
k8sClient.customResourceDefinitions().withName(crdName).get();
139146
if (customResourceDefinition == null) {

operator-framework/src/main/java/io/javaoperatorsdk/operator/OperatorException.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/OperatorException.java

File renamed without changes.

operator-framework/src/main/java/io/javaoperatorsdk/operator/api/Context.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Context.java

File renamed without changes.

operator-framework/src/main/java/io/javaoperatorsdk/operator/api/Controller.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java

Lines changed: 7 additions & 0 deletions

operator-framework/src/main/java/io/javaoperatorsdk/operator/api/DefaultContext.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/DefaultContext.java

File renamed without changes.

operator-framework/src/main/java/io/javaoperatorsdk/operator/api/DeleteControl.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/DeleteControl.java

File renamed without changes.

0 commit comments

Comments
 (0)