Skip to content

Commit a4b0efb

Browse files
metacosmcsviri
authored andcommitted
chore(docs): add some javadoc (#2452)
Signed-off-by: Chris Laprun <[email protected]>
1 parent 3601eec commit a4b0efb

File tree

11 files changed

+224
-86
lines changed

11 files changed

+224
-86
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractConfigurationService.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import io.javaoperatorsdk.operator.ReconcilerUtils;
1111
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
1212

13+
/**
14+
* An abstract implementation of {@link ConfigurationService} meant to ease custom implementations
15+
*/
1316
@SuppressWarnings("rawtypes")
1417
public class AbstractConfigurationService implements ConfigurationService {
1518
private final Map<String, ControllerConfiguration> configurations = new ConcurrentHashMap<>();
@@ -18,11 +21,11 @@ public class AbstractConfigurationService implements ConfigurationService {
1821
private Cloner cloner;
1922
private ExecutorServiceManager executorServiceManager;
2023

21-
public AbstractConfigurationService(Version version) {
24+
protected AbstractConfigurationService(Version version) {
2225
this(version, null);
2326
}
2427

25-
public AbstractConfigurationService(Version version, Cloner cloner) {
28+
protected AbstractConfigurationService(Version version, Cloner cloner) {
2629
this(version, cloner, null, null);
2730
}
2831

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

+109-57
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,68 @@ public interface ConfigurationService {
3636
Logger log = LoggerFactory.getLogger(ConfigurationService.class);
3737

3838
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+
}
39101

40102
/**
41103
* Retrieves the configuration associated with the specified reconciler
@@ -47,7 +109,6 @@ public interface ConfigurationService {
47109
*/
48110
<R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(Reconciler<R> reconciler);
49111

50-
51112
/**
52113
* Used to clone custom resources.
53114
*
@@ -131,8 +192,6 @@ default boolean checkCRDAndValidateLocalModel() {
131192
return false;
132193
}
133194

134-
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50;
135-
136195
/**
137196
* The number of threads the operator can spin out to dispatch reconciliation requests to
138197
* reconcilers with the default executors
@@ -143,8 +202,6 @@ default int concurrentReconciliationThreads() {
143202
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
144203
}
145204

146-
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
147-
148205
/**
149206
* Number of threads the operator can spin out to be used in the workflows with the default
150207
* executor.
@@ -155,27 +212,64 @@ default int concurrentWorkflowExecutorThreads() {
155212
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
156213
}
157214

215+
/**
216+
* Override to provide a custom {@link Metrics} implementation
217+
*
218+
* @return the {@link Metrics} implementation
219+
*/
158220
default Metrics getMetrics() {
159221
return Metrics.NOOP;
160222
}
161223

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+
*/
162231
default ExecutorService getExecutorService() {
163232
return Executors.newFixedThreadPool(concurrentReconciliationThreads());
164233
}
165234

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+
*/
166241
default ExecutorService getWorkflowExecutorService() {
167242
return Executors.newFixedThreadPool(concurrentWorkflowExecutorThreads());
168243
}
169244

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+
*/
170251
default boolean closeClientOnStop() {
171252
return true;
172253
}
173254

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+
*/
174261
@SuppressWarnings("rawtypes")
175262
default DependentResourceFactory dependentResourceFactory() {
176263
return DependentResourceFactory.DEFAULT;
177264
}
178265

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+
*/
179273
default Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
180274
return Optional.empty();
181275
}
@@ -231,65 +325,23 @@ default Optional<InformerStoppedHandler> getInformerStoppedHandler() {
231325
});
232326
}
233327

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+
*/
234335
@SuppressWarnings("rawtypes")
235336
default ManagedWorkflowFactory getWorkflowFactory() {
236337
return ManagedWorkflowFactory.DEFAULT;
237338
}
238339

239340
/**
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
287344
*/
288-
static ConfigurationService newOverriddenConfigurationService(
289-
Consumer<ConfigurationServiceOverrider> overrider) {
290-
return newOverriddenConfigurationService(new BaseConfigurationService(), overrider);
291-
}
292-
293345
default ExecutorServiceManager getExecutorServiceManager() {
294346
return new ExecutorServiceManager(this);
295347
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.java

+23-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
*/
1616
public interface DependentResource<R, P extends HasMetadata> {
1717

18+
/**
19+
* Computes a default name for the specified DependentResource class
20+
*
21+
* @param dependentResourceClass the DependentResource class for which we want to compute a
22+
* default name
23+
* @return the default name for the specified DependentResource class
24+
*/
25+
@SuppressWarnings("rawtypes")
26+
static String defaultNameFor(Class<? extends DependentResource> dependentResourceClass) {
27+
return dependentResourceClass.getName();
28+
}
29+
1830
/**
1931
* Reconciles the dependent resource given the desired primary state
2032
*
@@ -65,21 +77,23 @@ default Optional<R> getSecondaryResource(P primary, Context<P> context) {
6577
}
6678

6779
/**
68-
* Computes a default name for the specified DependentResource class
80+
* Determines whether resources associated with this dependent need explicit handling when
81+
* deleted, usually meaning that the dependent implements {@link Deleter}
6982
*
70-
* @param dependentResourceClass the DependentResource class for which we want to compute a
71-
* default name
72-
* @return the default name for the specified DependentResource class
83+
* @return {@code true} if explicit handling of resource deletion is needed, {@link false}
84+
* otherwise
7385
*/
74-
@SuppressWarnings("rawtypes")
75-
static String defaultNameFor(Class<? extends DependentResource> dependentResourceClass) {
76-
return dependentResourceClass.getName();
77-
}
78-
7986
default boolean isDeletable() {
8087
return this instanceof Deleter;
8188
}
8289

90+
91+
/**
92+
* Retrieves the name identifying this DependentResource implementation, useful to refer to this
93+
* in {@link io.javaoperatorsdk.operator.processing.dependent.workflow.Workflow} instances
94+
*
95+
* @return the name identifying this DependentResource implementation
96+
*/
8397
default String name() {
8498
return defaultNameFor(getClass());
8599
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/EventSourceHealthIndicator.java

+7
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
public interface EventSourceHealthIndicator {
44

5+
/**
6+
* Retrieves the health status of an
7+
* {@link io.javaoperatorsdk.operator.processing.event.source.EventSource}
8+
*
9+
* @return the health status
10+
* @see Status
11+
*/
512
Status getStatus();
613
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/health/Status.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.javaoperatorsdk.operator.health;
22

3+
/**
4+
* The health status of an {@link io.javaoperatorsdk.operator.processing.event.source.EventSource}
5+
*/
36
public enum Status {
47

58
HEALTHY, UNHEALTHY,

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
import io.javaoperatorsdk.operator.processing.dependent.Matcher.Result;
1717
import io.javaoperatorsdk.operator.processing.event.ResourceID;
1818

19+
/**
20+
* An abstract implementation of {@link DependentResource} to be used as base for custom
21+
* implementations, providing, in particular, the core {@link #reconcile(HasMetadata, Context)}
22+
* logic for dependents
23+
*
24+
* @param <R> the dependent resource type
25+
* @param <P> the associated primary resource type
26+
*/
1927
@Ignore
2028
public abstract class AbstractDependentResource<R, P extends HasMetadata>
2129
implements DependentResource<R, P>, NameSetter {
@@ -24,18 +32,16 @@ public abstract class AbstractDependentResource<R, P extends HasMetadata>
2432
private final boolean creatable = this instanceof Creator;
2533
private final boolean updatable = this instanceof Updater;
2634
private final boolean deletable = this instanceof Deleter;
27-
35+
private final DependentResourceReconciler<R, P> dependentResourceReconciler;
2836
protected Creator<R, P> creator;
2937
protected Updater<R, P> updater;
30-
private final DependentResourceReconciler<R, P> dependentResourceReconciler;
31-
3238
protected String name;
3339

34-
@SuppressWarnings({"unchecked"})
3540
protected AbstractDependentResource() {
3641
this(null);
3742
}
3843

44+
@SuppressWarnings("unchecked")
3945
protected AbstractDependentResource(String name) {
4046
creator = creatable ? (Creator<R, P>) this : null;
4147
updater = updatable ? (Updater<R, P>) this : null;
@@ -120,7 +126,8 @@ public Optional<R> getSecondaryResource(P primary, Context<P> context) {
120126
* secondary candidates for equality with the specified desired state, which might end up costly.
121127
*
122128
* @param secondaryResources to select the target resource from
123-
*
129+
* @param primary the primary resource
130+
* @param context the context in which this method is called
124131
* @return the matching secondary resource or {@link Optional#empty()} if none matches
125132
* @throws IllegalStateException if more than one candidate is found, in which case some other
126133
* mechanism might be necessary to distinguish between candidate secondary resources

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResource.java

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* dependent resource is to manage the number of secondary resources dynamically it implement
1313
* {@link Creator} and {@link Deleter} interfaces out of the box. A concrete dependent resource can
1414
* implement additionally also {@link Updater}.
15+
*
16+
* @param <R> the dependent resource type
17+
* @param <P> the primary resource type
1518
*/
1619
public interface BulkDependentResource<R, P extends HasMetadata> {
1720

0 commit comments

Comments
 (0)