@@ -33,6 +33,68 @@ public interface ConfigurationService {
33
33
Logger log = LoggerFactory .getLogger (ConfigurationService .class );
34
34
35
35
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
+ }
36
98
37
99
/**
38
100
* Retrieves the configuration associated with the specified reconciler
@@ -44,7 +106,6 @@ public interface ConfigurationService {
44
106
*/
45
107
<R extends HasMetadata > ControllerConfiguration <R > getConfigurationFor (Reconciler <R > reconciler );
46
108
47
-
48
109
/**
49
110
* Used to clone custom resources.
50
111
*
@@ -128,8 +189,6 @@ default boolean checkCRDAndValidateLocalModel() {
128
189
return false ;
129
190
}
130
191
131
- int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50 ;
132
-
133
192
/**
134
193
* The number of threads the operator can spin out to dispatch reconciliation requests to
135
194
* reconcilers with the default executors
@@ -140,8 +199,6 @@ default int concurrentReconciliationThreads() {
140
199
return DEFAULT_RECONCILIATION_THREADS_NUMBER ;
141
200
}
142
201
143
- int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER ;
144
-
145
202
/**
146
203
* Number of threads the operator can spin out to be used in the workflows with the default
147
204
* executor.
@@ -152,27 +209,64 @@ default int concurrentWorkflowExecutorThreads() {
152
209
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER ;
153
210
}
154
211
212
+ /**
213
+ * Override to provide a custom {@link Metrics} implementation
214
+ *
215
+ * @return the {@link Metrics} implementation
216
+ */
155
217
default Metrics getMetrics () {
156
218
return Metrics .NOOP ;
157
219
}
158
220
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
+ */
159
228
default ExecutorService getExecutorService () {
160
229
return Executors .newFixedThreadPool (concurrentReconciliationThreads ());
161
230
}
162
231
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
+ */
163
238
default ExecutorService getWorkflowExecutorService () {
164
239
return Executors .newFixedThreadPool (concurrentWorkflowExecutorThreads ());
165
240
}
166
241
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
+ */
167
248
default boolean closeClientOnStop () {
168
249
return true ;
169
250
}
170
251
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
+ */
171
258
@ SuppressWarnings ("rawtypes" )
172
259
default DependentResourceFactory dependentResourceFactory () {
173
260
return DependentResourceFactory .DEFAULT ;
174
261
}
175
262
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
+ */
176
270
default Optional <LeaderElectionConfiguration > getLeaderElectionConfiguration () {
177
271
return Optional .empty ();
178
272
}
@@ -228,65 +322,23 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
228
322
});
229
323
}
230
324
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
+ */
231
332
@ SuppressWarnings ("rawtypes" )
232
333
default ManagedWorkflowFactory getWorkflowFactory () {
233
334
return ManagedWorkflowFactory .DEFAULT ;
234
335
}
235
336
236
337
/**
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
284
341
*/
285
- static ConfigurationService newOverriddenConfigurationService (
286
- Consumer <ConfigurationServiceOverrider > overrider ) {
287
- return newOverriddenConfigurationService (new BaseConfigurationService (), overrider );
288
- }
289
-
290
342
default ExecutorServiceManager getExecutorServiceManager () {
291
343
return new ExecutorServiceManager (this );
292
344
}
0 commit comments