@@ -33,6 +33,68 @@ public interface ConfigurationService {
3333 Logger log = LoggerFactory .getLogger (ConfigurationService .class );
3434
3535 int DEFAULT_MAX_CONCURRENT_REQUEST = 512 ;
36+ /**
37+ * The default numbers of concurrent reconciliations
38+ */
39+ int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50 ;
40+ /**
41+ * The default number of threads used to process dependent workflows
42+ */
43+ int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER ;
44+
45+ /**
46+ * Creates a new {@link ConfigurationService} instance used to configure an
47+ * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
48+ * configuration and overriding specific aspects according to the provided
49+ * {@link ConfigurationServiceOverrider} instance.
50+ *
51+ * <p>
52+ * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
53+ * your Operator instance as the configuration service is set at creation time and cannot be
54+ * subsequently changed. As a result, overriding values this way after the Operator has been
55+ * configured will not take effect.
56+ * </p>
57+ *
58+ * @param baseConfiguration the {@link ConfigurationService} to start from
59+ * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
60+ * by the base configuration
61+ * @return a new {@link ConfigurationService} starting from the configuration provided as base but
62+ * with overridden values.
63+ */
64+ static ConfigurationService newOverriddenConfigurationService (
65+ ConfigurationService baseConfiguration ,
66+ Consumer <ConfigurationServiceOverrider > overrider ) {
67+ if (overrider != null ) {
68+ final var toOverride = new ConfigurationServiceOverrider (baseConfiguration );
69+ overrider .accept (toOverride );
70+ return toOverride .build ();
71+ }
72+ return baseConfiguration ;
73+ }
74+
75+ /**
76+ * Creates a new {@link ConfigurationService} instance used to configure an
77+ * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
78+ * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
79+ * instance.
80+ *
81+ * <p>
82+ * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
83+ * your Operator instance as the configuration service is set at creation time and cannot be
84+ * subsequently changed. As a result, overriding values this way after the Operator has been
85+ * configured will not take effect.
86+ * </p>
87+ *
88+ * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
89+ * by the default configuration
90+ * @return a new {@link ConfigurationService} overriding the default values with the ones provided
91+ * by the specified {@link ConfigurationServiceOverrider}
92+ * @since 4.4.0
93+ */
94+ static ConfigurationService newOverriddenConfigurationService (
95+ Consumer <ConfigurationServiceOverrider > overrider ) {
96+ return newOverriddenConfigurationService (new BaseConfigurationService (), overrider );
97+ }
3698
3799 /**
38100 * Retrieves the configuration associated with the specified reconciler
@@ -44,7 +106,6 @@ public interface ConfigurationService {
44106 */
45107 <R extends HasMetadata > ControllerConfiguration <R > getConfigurationFor (Reconciler <R > reconciler );
46108
47-
48109 /**
49110 * Used to clone custom resources.
50111 *
@@ -128,8 +189,6 @@ default boolean checkCRDAndValidateLocalModel() {
128189 return false ;
129190 }
130191
131- int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50 ;
132-
133192 /**
134193 * The number of threads the operator can spin out to dispatch reconciliation requests to
135194 * reconcilers with the default executors
@@ -140,8 +199,6 @@ default int concurrentReconciliationThreads() {
140199 return DEFAULT_RECONCILIATION_THREADS_NUMBER ;
141200 }
142201
143- int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER ;
144-
145202 /**
146203 * Number of threads the operator can spin out to be used in the workflows with the default
147204 * executor.
@@ -152,27 +209,64 @@ default int concurrentWorkflowExecutorThreads() {
152209 return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER ;
153210 }
154211
212+ /**
213+ * Override to provide a custom {@link Metrics} implementation
214+ *
215+ * @return the {@link Metrics} implementation
216+ */
155217 default Metrics getMetrics () {
156218 return Metrics .NOOP ;
157219 }
158220
221+ /**
222+ * Override to provide a custom {@link ExecutorService} implementation to change how threads
223+ * handle concurrent reconciliations
224+ *
225+ * @return the {@link ExecutorService} implementation to use for concurrent reconciliation
226+ * processing
227+ */
159228 default ExecutorService getExecutorService () {
160229 return Executors .newFixedThreadPool (concurrentReconciliationThreads ());
161230 }
162231
232+ /**
233+ * Override to provide a custom {@link ExecutorService} implementation to change how dependent
234+ * workflows are processed in parallel
235+ *
236+ * @return the {@link ExecutorService} implementation to use for dependent workflow processing
237+ */
163238 default ExecutorService getWorkflowExecutorService () {
164239 return Executors .newFixedThreadPool (concurrentWorkflowExecutorThreads ());
165240 }
166241
242+ /**
243+ * Determines whether the associated Kubernetes client should be closed when the associated
244+ * {@link io.javaoperatorsdk.operator.Operator} is stopped.
245+ *
246+ * @return {@code true} if the Kubernetes should be closed on stop, {@code false} otherwise
247+ */
167248 default boolean closeClientOnStop () {
168249 return true ;
169250 }
170251
252+ /**
253+ * Override to provide a custom {@link DependentResourceFactory} implementation to change how
254+ * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} are instantiated
255+ *
256+ * @return the custom {@link DependentResourceFactory} implementation
257+ */
171258 @ SuppressWarnings ("rawtypes" )
172259 default DependentResourceFactory dependentResourceFactory () {
173260 return DependentResourceFactory .DEFAULT ;
174261 }
175262
263+ /**
264+ * Retrieves the optional {@link LeaderElectionConfiguration} to specify how the associated
265+ * {@link io.javaoperatorsdk.operator.Operator} handles leader election to ensure only one
266+ * instance of the operator runs on the cluster at any given time
267+ *
268+ * @return the {@link LeaderElectionConfiguration}
269+ */
176270 default Optional <LeaderElectionConfiguration > getLeaderElectionConfiguration () {
177271 return Optional .empty ();
178272 }
@@ -228,65 +322,23 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
228322 });
229323 }
230324
325+ /**
326+ * Override to provide a custom {@link ManagedWorkflowFactory} implementation to change how
327+ * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow} are
328+ * instantiated
329+ *
330+ * @return the custom {@link ManagedWorkflowFactory} implementation
331+ */
231332 @ SuppressWarnings ("rawtypes" )
232333 default ManagedWorkflowFactory getWorkflowFactory () {
233334 return ManagedWorkflowFactory .DEFAULT ;
234335 }
235336
236337 /**
237- * Creates a new {@link ConfigurationService} instance used to configure an
238- * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
239- * configuration and overriding specific aspects according to the provided
240- * {@link ConfigurationServiceOverrider} instance.
241- *
242- * <p>
243- * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
244- * your Operator instance as the configuration service is set at creation time and cannot be
245- * subsequently changed. As a result, overriding values this way after the Operator has been
246- * configured will not take effect.
247- * </p>
248- *
249- * @param baseConfiguration the {@link ConfigurationService} to start from
250- * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
251- * by the base configuration
252- * @return a new {@link ConfigurationService} starting from the configuration provided as base but
253- * with overridden values.
254- */
255- static ConfigurationService newOverriddenConfigurationService (
256- ConfigurationService baseConfiguration ,
257- Consumer <ConfigurationServiceOverrider > overrider ) {
258- if (overrider != null ) {
259- final var toOverride = new ConfigurationServiceOverrider (baseConfiguration );
260- overrider .accept (toOverride );
261- return toOverride .build ();
262- }
263- return baseConfiguration ;
264- }
265-
266- /**
267- * Creates a new {@link ConfigurationService} instance used to configure an
268- * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
269- * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
270- * instance.
271- *
272- * <p>
273- * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
274- * your Operator instance as the configuration service is set at creation time and cannot be
275- * subsequently changed. As a result, overriding values this way after the Operator has been
276- * configured will not take effect.
277- * </p>
278- *
279- * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
280- * by the default configuration
281- * @return a new {@link ConfigurationService} overriding the default values with the ones provided
282- * by the specified {@link ConfigurationServiceOverrider}
283- * @since 4.4.0
338+ * Override to provide a custom {@link ExecutorServiceManager} implementation
339+ *
340+ * @return the custom {@link ExecutorServiceManager} implementation
284341 */
285- static ConfigurationService newOverriddenConfigurationService (
286- Consumer <ConfigurationServiceOverrider > overrider ) {
287- return newOverriddenConfigurationService (new BaseConfigurationService (), overrider );
288- }
289-
290342 default ExecutorServiceManager getExecutorServiceManager () {
291343 return new ExecutorServiceManager (this );
292344 }
0 commit comments