@@ -36,6 +36,68 @@ public interface ConfigurationService {
36
36
Logger log = LoggerFactory .getLogger (ConfigurationService .class );
37
37
38
38
int DEFAULT_MAX_CONCURRENT_REQUEST = 512 ;
39
+ /**
40
+ * The default numbers of concurrent reconciliations
41
+ */
42
+ int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50 ;
43
+ /**
44
+ * The default number of threads used to process dependent workflows
45
+ */
46
+ int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER ;
47
+
48
+ /**
49
+ * Creates a new {@link ConfigurationService} instance used to configure an
50
+ * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
51
+ * configuration and overriding specific aspects according to the provided
52
+ * {@link ConfigurationServiceOverrider} instance.
53
+ *
54
+ * <p>
55
+ * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
56
+ * your Operator instance as the configuration service is set at creation time and cannot be
57
+ * subsequently changed. As a result, overriding values this way after the Operator has been
58
+ * configured will not take effect.
59
+ * </p>
60
+ *
61
+ * @param baseConfiguration the {@link ConfigurationService} to start from
62
+ * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
63
+ * by the base configuration
64
+ * @return a new {@link ConfigurationService} starting from the configuration provided as base but
65
+ * with overridden values.
66
+ */
67
+ static ConfigurationService newOverriddenConfigurationService (
68
+ ConfigurationService baseConfiguration ,
69
+ Consumer <ConfigurationServiceOverrider > overrider ) {
70
+ if (overrider != null ) {
71
+ final var toOverride = new ConfigurationServiceOverrider (baseConfiguration );
72
+ overrider .accept (toOverride );
73
+ return toOverride .build ();
74
+ }
75
+ return baseConfiguration ;
76
+ }
77
+
78
+ /**
79
+ * Creates a new {@link ConfigurationService} instance used to configure an
80
+ * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
81
+ * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
82
+ * instance.
83
+ *
84
+ * <p>
85
+ * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
86
+ * your Operator instance as the configuration service is set at creation time and cannot be
87
+ * subsequently changed. As a result, overriding values this way after the Operator has been
88
+ * configured will not take effect.
89
+ * </p>
90
+ *
91
+ * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
92
+ * by the default configuration
93
+ * @return a new {@link ConfigurationService} overriding the default values with the ones provided
94
+ * by the specified {@link ConfigurationServiceOverrider}
95
+ * @since 4.4.0
96
+ */
97
+ static ConfigurationService newOverriddenConfigurationService (
98
+ Consumer <ConfigurationServiceOverrider > overrider ) {
99
+ return newOverriddenConfigurationService (new BaseConfigurationService (), overrider );
100
+ }
39
101
40
102
/**
41
103
* Retrieves the configuration associated with the specified reconciler
@@ -47,7 +109,6 @@ public interface ConfigurationService {
47
109
*/
48
110
<R extends HasMetadata > ControllerConfiguration <R > getConfigurationFor (Reconciler <R > reconciler );
49
111
50
-
51
112
/**
52
113
* Used to clone custom resources.
53
114
*
@@ -131,8 +192,6 @@ default boolean checkCRDAndValidateLocalModel() {
131
192
return false ;
132
193
}
133
194
134
- int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50 ;
135
-
136
195
/**
137
196
* The number of threads the operator can spin out to dispatch reconciliation requests to
138
197
* reconcilers with the default executors
@@ -143,8 +202,6 @@ default int concurrentReconciliationThreads() {
143
202
return DEFAULT_RECONCILIATION_THREADS_NUMBER ;
144
203
}
145
204
146
- int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER ;
147
-
148
205
/**
149
206
* Number of threads the operator can spin out to be used in the workflows with the default
150
207
* executor.
@@ -155,27 +212,64 @@ default int concurrentWorkflowExecutorThreads() {
155
212
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER ;
156
213
}
157
214
215
+ /**
216
+ * Override to provide a custom {@link Metrics} implementation
217
+ *
218
+ * @return the {@link Metrics} implementation
219
+ */
158
220
default Metrics getMetrics () {
159
221
return Metrics .NOOP ;
160
222
}
161
223
224
+ /**
225
+ * Override to provide a custom {@link ExecutorService} implementation to change how threads
226
+ * handle concurrent reconciliations
227
+ *
228
+ * @return the {@link ExecutorService} implementation to use for concurrent reconciliation
229
+ * processing
230
+ */
162
231
default ExecutorService getExecutorService () {
163
232
return Executors .newFixedThreadPool (concurrentReconciliationThreads ());
164
233
}
165
234
235
+ /**
236
+ * Override to provide a custom {@link ExecutorService} implementation to change how dependent
237
+ * workflows are processed in parallel
238
+ *
239
+ * @return the {@link ExecutorService} implementation to use for dependent workflow processing
240
+ */
166
241
default ExecutorService getWorkflowExecutorService () {
167
242
return Executors .newFixedThreadPool (concurrentWorkflowExecutorThreads ());
168
243
}
169
244
245
+ /**
246
+ * Determines whether the associated Kubernetes client should be closed when the associated
247
+ * {@link io.javaoperatorsdk.operator.Operator} is stopped.
248
+ *
249
+ * @return {@code true} if the Kubernetes should be closed on stop, {@code false} otherwise
250
+ */
170
251
default boolean closeClientOnStop () {
171
252
return true ;
172
253
}
173
254
255
+ /**
256
+ * Override to provide a custom {@link DependentResourceFactory} implementation to change how
257
+ * {@link io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource} are instantiated
258
+ *
259
+ * @return the custom {@link DependentResourceFactory} implementation
260
+ */
174
261
@ SuppressWarnings ("rawtypes" )
175
262
default DependentResourceFactory dependentResourceFactory () {
176
263
return DependentResourceFactory .DEFAULT ;
177
264
}
178
265
266
+ /**
267
+ * Retrieves the optional {@link LeaderElectionConfiguration} to specify how the associated
268
+ * {@link io.javaoperatorsdk.operator.Operator} handles leader election to ensure only one
269
+ * instance of the operator runs on the cluster at any given time
270
+ *
271
+ * @return the {@link LeaderElectionConfiguration}
272
+ */
179
273
default Optional <LeaderElectionConfiguration > getLeaderElectionConfiguration () {
180
274
return Optional .empty ();
181
275
}
@@ -231,65 +325,23 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
231
325
});
232
326
}
233
327
328
+ /**
329
+ * Override to provide a custom {@link ManagedWorkflowFactory} implementation to change how
330
+ * {@link io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflow} are
331
+ * instantiated
332
+ *
333
+ * @return the custom {@link ManagedWorkflowFactory} implementation
334
+ */
234
335
@ SuppressWarnings ("rawtypes" )
235
336
default ManagedWorkflowFactory getWorkflowFactory () {
236
337
return ManagedWorkflowFactory .DEFAULT ;
237
338
}
238
339
239
340
/**
240
- * Creates a new {@link ConfigurationService} instance used to configure an
241
- * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the specified base
242
- * configuration and overriding specific aspects according to the provided
243
- * {@link ConfigurationServiceOverrider} instance.
244
- *
245
- * <p>
246
- * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
247
- * your Operator instance as the configuration service is set at creation time and cannot be
248
- * subsequently changed. As a result, overriding values this way after the Operator has been
249
- * configured will not take effect.
250
- * </p>
251
- *
252
- * @param baseConfiguration the {@link ConfigurationService} to start from
253
- * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
254
- * by the base configuration
255
- * @return a new {@link ConfigurationService} starting from the configuration provided as base but
256
- * with overridden values.
257
- */
258
- static ConfigurationService newOverriddenConfigurationService (
259
- ConfigurationService baseConfiguration ,
260
- Consumer <ConfigurationServiceOverrider > overrider ) {
261
- if (overrider != null ) {
262
- final var toOverride = new ConfigurationServiceOverrider (baseConfiguration );
263
- overrider .accept (toOverride );
264
- return toOverride .build ();
265
- }
266
- return baseConfiguration ;
267
- }
268
-
269
- /**
270
- * Creates a new {@link ConfigurationService} instance used to configure an
271
- * {@link io.javaoperatorsdk.operator.Operator} instance, starting from the default configuration
272
- * and overriding specific aspects according to the provided {@link ConfigurationServiceOverrider}
273
- * instance.
274
- *
275
- * <p>
276
- * <em>NOTE:</em> This overriding mechanism should only be used <strong>before</strong> creating
277
- * your Operator instance as the configuration service is set at creation time and cannot be
278
- * subsequently changed. As a result, overriding values this way after the Operator has been
279
- * configured will not take effect.
280
- * </p>
281
- *
282
- * @param overrider the {@link ConfigurationServiceOverrider} used to change the values provided
283
- * by the default configuration
284
- * @return a new {@link ConfigurationService} overriding the default values with the ones provided
285
- * by the specified {@link ConfigurationServiceOverrider}
286
- * @since 4.4.0
341
+ * Override to provide a custom {@link ExecutorServiceManager} implementation
342
+ *
343
+ * @return the custom {@link ExecutorServiceManager} implementation
287
344
*/
288
- static ConfigurationService newOverriddenConfigurationService (
289
- Consumer <ConfigurationServiceOverrider > overrider ) {
290
- return newOverriddenConfigurationService (new BaseConfigurationService (), overrider );
291
- }
292
-
293
345
default ExecutorServiceManager getExecutorServiceManager () {
294
346
return new ExecutorServiceManager (this );
295
347
}
0 commit comments