-
Notifications
You must be signed in to change notification settings - Fork 224
Extract controller configuration handling and provide Quarkus extension #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
metacosm
merged 83 commits into
operator-framework:master
from
halkyonio:quarkus-support
Dec 18, 2020
Merged
Changes from all commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
31fe80c
refactor: extract default finalizer name logic into own method
metacosm 07e4741
feat: Controllers can now be named for configuration purposes
metacosm 89add61
feat: encapsulate controllers' configuration behind an interface
metacosm 08f87a6
refactor: use controller's configuration instead of ControllerUtils
metacosm 240d1df
fix: Controller doesn't have resource class field anymore
metacosm e5725ec
refactor: move configuration retrieval to ConfigurationService
metacosm 3042075
refactor: rename DefaultConfiguration to AnnotationConfiguration
metacosm 8629f8d
feat: add RetryConfiguration
metacosm a42d002
fix: change default watchAllNamespaces implementation, add constant
metacosm 0ffeee9
feat: add cluster scope and namespaces support to Controller
metacosm aaf8a53
refactor: extract default controller name generation to ControllerUtils
metacosm e310600
feat: initial rewrite of Spring Boot auto-configuration for new format
metacosm 48870b7
fix: provide reasonable defaults
metacosm 819e054
fix: update to new format
metacosm 859e983
fix: update to new format
metacosm 685ba78
feat: initial commit for Quarkus extension
metacosm a0890ee
feat: add getDoneableClass on ControllerConfiguration
metacosm 1375740
feat: add initial quarkus (not working) sample
metacosm b6dcbcb
feat: make jar indexable by Quarkus
metacosm fe42b61
fix: remove unneeded Spring dependency from parent pom
metacosm c07e262
chore: better names for quarkus extension modules
metacosm 6a43c27
chore: upgrade to Quarkus 1.10.2
metacosm 0b5af44
feat: add getDefaultResourceControllerName method
metacosm f309d80
feat: import common sample classes in quarkus sample
metacosm d28e3c0
feat: initial support for build-time configuration, still needs work
metacosm e968f10
feat: use Doneable from configuration
metacosm 912433f
feat: add fromConfiguration factory method
metacosm 86449d0
feat: add register method that simply uses the controller's config
metacosm 7c7b719
feat: register the controllers using their defined configuration
metacosm 38e7088
refactor: move config package to api
metacosm c81e43c
refactor: extract api module
metacosm d7b0224
refactor: move runtime configuration handling into separate module
metacosm e08d060
fix: code organization and missing changes from rebase
metacosm 7d21132
fix: more re-organization and fixes after rebase
metacosm 8a26cc8
fix: update auto-service to avoid guava conflict with compile-testing
metacosm 34c8b62
refactor: use function reference
metacosm 02fd97b
fix: extract TestCustomResource to work around issue #249
metacosm f3a7924
fix: add runtime-configuration dependency to process controller
metacosm 32a4dd7
feat: add output of controller class when doneable cannot be found
metacosm 61a271b
feat: switch to SyntheticBean (sync commit)
metacosm 777b53a
fix: use default configuration instead of creating one
metacosm 691d3a1
chore: remove unneeded class
metacosm a87b3e3
fix: use classes to make sure we have the proper names
metacosm da34720
fix: make QuarkusControllerConfiguration serializable
metacosm 38e60b3
fix: mark configuration service as runtime init
metacosm 5754bbb
fix: load class using TCCL
metacosm f8c5929
fix: doneable is generated at the end of build, load it when needed
metacosm d14761f
feat: remove ClientConfiguration, replace it by fabric8 client config
metacosm 52d99db
fix: remove unneeded ResourceControllerBuildItem
metacosm 4db2a49
chore: update to Quarkus 1.10.3
metacosm d62dca1
feat: split extension into several steps
metacosm bc020cd
fix: register controller as bean, not CR class… :facepalm:
metacosm 96e6f58
fix: wait for configuration service before creating the operator
metacosm 2132c4a
fix: avoid unnecessarily loading classes at build time
metacosm 4601f94
fix: Quarkus doesn't like anonymous interface implementations
metacosm 736da3c
fix: make QuarkusControllerConfiguration RecordableConstructor-enabled
metacosm 407a241
fix: make QuarkusConfigurationService also provide ConfigurationService
metacosm 75150db
refactor: simplify and streamline things
metacosm 53fccb9
feat: check that injection properly works
metacosm 8bebad0
chore: re-format
metacosm 5ae707f
chore: use proper version
metacosm 1e905af
chore: remove wrong imports
metacosm 9c95948
chore: restore back to compiling state after rebase
metacosm cfebbc7
fix: wrong parent version
metacosm 8efc8e2
feat: automatically register detected controllers
metacosm eedf0d5
chore: remove unneeded dependencies
metacosm 94f3bdd
fix: wrong/duplicated imports
metacosm dbc5394
fix: update versions in POM files
metacosm c98f825
fix: restore to compiling state after rebase
metacosm 8f1c8de
fix: move compile-fixtures to proper spot
metacosm b3066f2
chore: move integration tests to runtime-configuration module
metacosm 465b53f
refactor: fold api module back into operator-framework
metacosm 85c466f
refactor: move classes back to their previous spot
metacosm 495ff39
refactor: rename operator-framework module to operator-framework-core
metacosm 9c1c559
refactor: rename runtime-configuration to operator-framework
metacosm bebc154
refactor: rename SB starter to follow SB conventions
metacosm 09e3446
refactor: rename quarkus extension for consistency
metacosm 257f4aa
refactor: move test sample / duplicate some to fix integration tests
metacosm 0b1b421
chore: clean-up
metacosm 47cbc10
fix: move CRD descriptors where they're needed
metacosm d0e3774
fix: move tests where appropriate
metacosm 08b00a3
chore: use static imports
metacosm 06033fc
doc: update README
metacosm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.javaoperatorsdk</groupId> | ||
<artifactId>java-operator-sdk</artifactId> | ||
<version>1.5.1-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>operator-framework-core</artifactId> | ||
<name>Operator SDK - Framework - Core</name> | ||
<description>Core framework for implementing Kubernetes operators</description> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>openshift-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<version>2.13.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.18.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
35 changes: 35 additions & 0 deletions
35
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.javaoperatorsdk.operator; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.javaoperatorsdk.operator.api.ResourceController; | ||
import java.util.Locale; | ||
|
||
public class ControllerUtils { | ||
|
||
private static final String FINALIZER_NAME_SUFFIX = "/finalizer"; | ||
|
||
public static String getDefaultFinalizerName(String crdName) { | ||
return crdName + FINALIZER_NAME_SUFFIX; | ||
} | ||
|
||
public static boolean hasGivenFinalizer(CustomResource resource, String finalizer) { | ||
return resource.getMetadata().getFinalizers() != null | ||
&& resource.getMetadata().getFinalizers().contains(finalizer); | ||
} | ||
|
||
public static String getDefaultNameFor(ResourceController controller) { | ||
return getDefaultNameFor(controller.getClass()); | ||
} | ||
|
||
public static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) { | ||
return getDefaultResourceControllerName(controllerClass.getSimpleName()); | ||
} | ||
|
||
public static String getDefaultResourceControllerName(String rcControllerClassName) { | ||
final var lastDot = rcControllerClassName.lastIndexOf('.'); | ||
if (lastDot > 0) { | ||
rcControllerClassName = rcControllerClassName.substring(lastDot); | ||
} | ||
return rcControllerClassName.toLowerCase(Locale.ROOT); | ||
} | ||
} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
...ework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.javaoperatorsdk.operator.api.ResourceController; | ||
|
||
public interface ConfigurationService { | ||
|
||
<R extends CustomResource> ControllerConfiguration<R> getConfigurationFor( | ||
ResourceController<R> controller); | ||
|
||
default Config getClientConfiguration() { | ||
return Config.autoConfigure(null); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...rk-core/src/main/java/io/javaoperatorsdk/operator/api/config/ControllerConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
import io.fabric8.kubernetes.client.CustomResource; | ||
import io.fabric8.kubernetes.client.CustomResourceDoneable; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public interface ControllerConfiguration<R extends CustomResource> { | ||
|
||
String WATCH_ALL_NAMESPACES_MARKER = "ALL_NAMESPACES"; | ||
|
||
String getName(); | ||
|
||
String getCRDName(); | ||
|
||
String getFinalizer(); | ||
|
||
boolean isGenerationAware(); | ||
|
||
Class<R> getCustomResourceClass(); | ||
|
||
Class<? extends CustomResourceDoneable<R>> getDoneableClass(); | ||
|
||
default boolean isClusterScoped() { | ||
return false; | ||
} | ||
|
||
default Set<String> getNamespaces() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
default boolean watchAllNamespaces() { | ||
return getNamespaces().contains(WATCH_ALL_NAMESPACES_MARKER); | ||
} | ||
|
||
default RetryConfiguration getRetryConfiguration() { | ||
return RetryConfiguration.DEFAULT; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultRetryConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.javaoperatorsdk.operator.api.config; | ||
|
||
public class DefaultRetryConfiguration implements RetryConfiguration {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really easy to understand what DefaultConfigurationService is :(.
I think there is a way to make better before the final release.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is to be able to provide the configuration from the annotation processor in the absence of injection. What would you propose to make this simpler/clearer?
The same thing could apply to
DefaultKubernetesClient
for that matter… it shouldn't be exposed either, IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigurationProvider
might be a better name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the user's point of view, there is only one ConfigurationService in the classpath belonging to the imported dependency, so would be best to hide it completely from the user by default.
I'm fine with the current approach and naming though, can become simpler in next iterations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@psycho-ir the problem is that we cannot put it there by default because then it would be pulled in by the Quarkus implementation as well, which is exactly what I'm trying to avoid 😄