From b0c8c494c5892ba5e8edd42e5ac3e6b9244cde1a Mon Sep 17 00:00:00 2001 From: csviri Date: Thu, 17 Aug 2023 09:33:49 +0200 Subject: [PATCH 1/2] docs: remoce ConfigurationServiceProvider obsolete usage --- docs/documentation/configuration.md | 23 ++++++------------- docs/documentation/faq.md | 3 +-- docs/documentation/features.md | 2 +- .../operator/sample/WebPageOperator.java | 1 + 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/docs/documentation/configuration.md b/docs/documentation/configuration.md index 52ce725ad7..44d233de4a 100644 --- a/docs/documentation/configuration.md +++ b/docs/documentation/configuration.md @@ -7,7 +7,7 @@ permalink: /docs/configuration # Configuration options -The Java Operator SDK (JOSDK for short) provides several abstractions that work great out of the +The Java Operator SDK (JOSDK) provides several abstractions that work great out of the box. However, while we strive to cover the most common cases with the default behavior, we also recognize that that default behavior is not always what any given user might want for their operator. Numerous configuration options are therefore provided to help people tailor the @@ -23,29 +23,20 @@ Configuration options act at several levels, depending on which behavior you wis ## Operator-level configuration Configuration that impacts the whole operator is performed via the `ConfigurationService` class. -An instance is provided by the `ConfigurationServiceProvider.instance()` method. This is the -normal way for user-code to retrieve the current `ConfigurationService` instance. Sensible -defaults are provided but you can change the default behavior by overriding the current -configuration using `ConfigurationServiceProvider.overrideCurrent` method, providing a -`ConfigurationServiceOverrider` `Consumer` that will apply the modifications you wish to perform -on the configuration. +`ConfigurationService` is an abstract class, and the implementation can be different based +on which flavor of the framework is used. For example Quarkus Operator SDK replaces the +default implementation. Configurations are initialized with sensible defaults, but can +be changed during initialization. For instance, if you wish to not validate that the CRDs are present on your cluster when the operator starts and configure leader election, you would do something similar to: ```java -ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false) +Operator operator = new Operator( override -> override + .checkingCRDAndValidateLocalModel(false) .withLeaderElectionConfiguration(new LeaderElectionConfiguration("bar", "barNS"))); ``` -Note that you can also obtain the same result by passing the `ConfigurationServiceOverrider` -`Consumer` instance to the `Operator` constructor: - -```java -new Operator(o -> o.checkingCRDAndValidateLocalModel(false) - .withLeaderElectionConfiguration(new LeaderElectionConfiguration("bar","barNS"))); -``` - ## Reconciler-level configuration While reconcilers are typically configured using the `@ControllerConfiguration` annotation, it diff --git a/docs/documentation/faq.md b/docs/documentation/faq.md index 9a291df329..bbe09dc633 100644 --- a/docs/documentation/faq.md +++ b/docs/documentation/faq.md @@ -73,10 +73,9 @@ Furthermore, you may not be able to list CRDs at startup which is required when is `true` (`false` by default). To disable, set it to `false` at [Operator-level configuration](./configuration.md#operator-level-configuration): ```java -ConfigurationServiceProvider.overrideCurrent(o -> o.checkingCRDAndValidateLocalModel(false)); +Operator operator = new Operator( override -> override.checkingCRDAndValidateLocalModel(false)); ``` - ### Q: How to fix `sun.security.provider.certpath.SunCertPathBuilderException` on Rancher Desktop and k3d/k3s Kubernetes It's a common issue when using k3d and the fabric8 client tries to connect to the cluster an exception is thrown: diff --git a/docs/documentation/features.md b/docs/documentation/features.md index e94cdcdb81..bce21a61aa 100644 --- a/docs/documentation/features.md +++ b/docs/documentation/features.md @@ -769,7 +769,7 @@ follows: ```java Metrics metrics= …; -ConfigurationServiceProvider.overrideCurrent(overrider->overrider.withMetrics(metrics)); +Operator operator = new Operator(client, o -> o.withMetrics()); ``` ### Micrometer implementation diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java index 28a0b4e84f..6c9876e24d 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.net.InetSocketAddress; +import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 881e66fb33d33e4c2f63ba2deba5bd5b8602d2ca Mon Sep 17 00:00:00 2001 From: csviri Date: Thu, 17 Aug 2023 10:41:22 +0200 Subject: [PATCH 2/2] fix --- .../java/io/javaoperatorsdk/operator/sample/WebPageOperator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java index 6c9876e24d..28a0b4e84f 100644 --- a/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java +++ b/sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.net.InetSocketAddress; -import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory;