-
Notifications
You must be signed in to change notification settings - Fork 220
feat(quarkus): add support for externalized configuration #306
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fc33df
feat(quarkus): add support for externalized configuration
metacosm 98ec565
docs: add extract documentation
metacosm 71c17b9
refactor: make DelegatingRetryConfiguration.resolve static
metacosm b5258eb
refactor: DelegatingRetryConfiguration -> RetryConfigurationResolver
metacosm ca4cb01
fix(build): building the test app is handled by the tests
metacosm 22ccebc
fix: add default value for generationAware
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
102 changes: 102 additions & 0 deletions
102
...main/java/io/javaoperatorsdk/quarkus/extension/deployment/RetryConfigurationResolver.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,102 @@ | ||
package io.javaoperatorsdk.quarkus.extension.deployment; | ||
|
||
import io.javaoperatorsdk.operator.api.config.RetryConfiguration; | ||
import io.javaoperatorsdk.quarkus.extension.ExternalIntervalConfiguration; | ||
import io.javaoperatorsdk.quarkus.extension.ExternalRetryConfiguration; | ||
import io.javaoperatorsdk.quarkus.extension.PlainRetryConfiguration; | ||
import java.util.Optional; | ||
|
||
class RetryConfigurationResolver implements RetryConfiguration { | ||
|
||
private final RetryConfiguration delegate; | ||
|
||
private RetryConfigurationResolver(Optional<ExternalRetryConfiguration> retry) { | ||
delegate = | ||
retry | ||
.<RetryConfiguration>map(ExternalRetryConfigurationAdapter::new) | ||
.orElse(RetryConfiguration.DEFAULT); | ||
} | ||
|
||
public static RetryConfiguration resolve(Optional<ExternalRetryConfiguration> retry) { | ||
final var delegate = new RetryConfigurationResolver(retry); | ||
return new PlainRetryConfiguration( | ||
delegate.getMaxAttempts(), | ||
delegate.getInitialInterval(), | ||
delegate.getIntervalMultiplier(), | ||
delegate.getMaxInterval()); | ||
} | ||
|
||
@Override | ||
public int getMaxAttempts() { | ||
return delegate.getMaxAttempts(); | ||
} | ||
|
||
@Override | ||
public long getInitialInterval() { | ||
return delegate.getInitialInterval(); | ||
} | ||
|
||
@Override | ||
public double getIntervalMultiplier() { | ||
return delegate.getIntervalMultiplier(); | ||
} | ||
|
||
@Override | ||
public long getMaxInterval() { | ||
return delegate.getMaxInterval(); | ||
} | ||
|
||
private static class ExternalRetryConfigurationAdapter implements RetryConfiguration { | ||
|
||
private final int maxAttempts; | ||
private final IntervalConfigurationAdapter interval; | ||
|
||
public ExternalRetryConfigurationAdapter(ExternalRetryConfiguration config) { | ||
maxAttempts = config.maxAttempts.orElse(RetryConfiguration.DEFAULT.getMaxAttempts()); | ||
interval = | ||
config | ||
.interval | ||
.map(IntervalConfigurationAdapter::new) | ||
.orElse(new IntervalConfigurationAdapter()); | ||
} | ||
|
||
@Override | ||
public int getMaxAttempts() { | ||
return maxAttempts; | ||
} | ||
|
||
@Override | ||
public long getInitialInterval() { | ||
return interval.initial; | ||
} | ||
|
||
@Override | ||
public double getIntervalMultiplier() { | ||
return interval.multiplier; | ||
} | ||
|
||
@Override | ||
public long getMaxInterval() { | ||
return interval.max; | ||
} | ||
} | ||
|
||
private static class IntervalConfigurationAdapter { | ||
|
||
private final long initial; | ||
private final double multiplier; | ||
private final long max; | ||
|
||
IntervalConfigurationAdapter(ExternalIntervalConfiguration config) { | ||
initial = config.initial.orElse(RetryConfiguration.DEFAULT.getInitialInterval()); | ||
multiplier = config.multiplier.orElse(RetryConfiguration.DEFAULT.getIntervalMultiplier()); | ||
max = config.max.orElse(RetryConfiguration.DEFAULT.getMaxInterval()); | ||
} | ||
|
||
IntervalConfigurationAdapter() { | ||
this.initial = RetryConfiguration.DEFAULT.getInitialInterval(); | ||
this.multiplier = RetryConfiguration.DEFAULT.getIntervalMultiplier(); | ||
this.max = RetryConfiguration.DEFAULT.getMaxInterval(); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ion/runtime/src/main/java/io/javaoperatorsdk/quarkus/extension/ExternalConfiguration.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,13 @@ | ||
package io.javaoperatorsdk.quarkus.extension; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
import java.util.Map; | ||
|
||
@ConfigRoot(name = "operator-sdk", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) | ||
public class ExternalConfiguration { | ||
|
||
/** Maps a controller name to its configuration. */ | ||
@ConfigItem public Map<String, ExternalControllerConfiguration> controllers; | ||
} |
34 changes: 34 additions & 0 deletions
34
...e/src/main/java/io/javaoperatorsdk/quarkus/extension/ExternalControllerConfiguration.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,34 @@ | ||
package io.javaoperatorsdk.quarkus.extension; | ||
|
||
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration; | ||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@ConfigGroup | ||
public class ExternalControllerConfiguration { | ||
|
||
/** | ||
* An optional list of comma-separated namespace names the controller should watch. If the list | ||
* contains {@link ControllerConfiguration#WATCH_ALL_NAMESPACES_MARKER} then the controller will | ||
* watch all namespaces. | ||
*/ | ||
@ConfigItem public Optional<List<String>> namespaces; | ||
|
||
/** | ||
* The optional name of the finalizer for the controller. If none is provided, one will be | ||
* automatically generated. | ||
*/ | ||
@ConfigItem public Optional<String> finalizer; | ||
|
||
/** | ||
* Whether the controller should only process events if the associated resource generation has | ||
* increased since last reconciliation, otherwise will process all events. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public Optional<Boolean> generationAware; | ||
|
||
/** The optional controller retry configuration */ | ||
public Optional<ExternalRetryConfiguration> retry; | ||
} |
21 changes: 21 additions & 0 deletions
21
...ime/src/main/java/io/javaoperatorsdk/quarkus/extension/ExternalIntervalConfiguration.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,21 @@ | ||
package io.javaoperatorsdk.quarkus.extension; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import java.util.Optional; | ||
|
||
@ConfigGroup | ||
public class ExternalIntervalConfiguration { | ||
|
||
/** The initial interval that the controller waits for before attempting the first retry */ | ||
@ConfigItem public Optional<Long> initial; | ||
|
||
/** The value by which the initial interval is multiplied by for each retry */ | ||
@ConfigItem public Optional<Double> multiplier; | ||
|
||
/** | ||
* The maximum interval that the controller will wait for before attempting a retry, regardless of | ||
* all other configuration | ||
*/ | ||
@ConfigItem public Optional<Long> max; | ||
} |
15 changes: 15 additions & 0 deletions
15
...untime/src/main/java/io/javaoperatorsdk/quarkus/extension/ExternalRetryConfiguration.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.quarkus.extension; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import java.util.Optional; | ||
|
||
@ConfigGroup | ||
public class ExternalRetryConfiguration { | ||
|
||
/** How many times an operation should be retried before giving up */ | ||
@ConfigItem public Optional<Integer> maxAttempts; | ||
|
||
/** The configuration of the retry interval. */ | ||
@ConfigItem public Optional<ExternalIntervalConfiguration> interval; | ||
} |
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.
How about if this list is empty then the controller watches all namespaces? I think watching all namespaces is a sensible default as this will mostly be controlled by RBAC anyway by cluster admins not by configuring the operator.
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.
At the moment the default behavior is to watch the namespace the client is connected to (which should be the namespace the operator is deployed in), the idea being that you don't need to setup RBAC by default, which should make it easier to experiment with.
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.
Ok let's leave it like that for now. We could check what's the default in the operator-sdk and just run with that 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.
I will address this in #303