Skip to content

Commit 46cd7ee

Browse files
committed
cleanup configs
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent aefcbc6 commit 46cd7ee

File tree

5 files changed

+28
-56
lines changed

5 files changed

+28
-56
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class InformerConfiguration<R extends HasMetadata> {
5454
private ItemStore<R> itemStore;
5555
private Long informerListLimit;
5656
private FieldSelector fieldSelector;
57-
private boolean comparableResourceVersions;
57+
private Boolean comparableResourceVersions;
5858
private Duration obsoleteResourceCacheCheckInterval;
5959

6060
protected InformerConfiguration(
@@ -70,7 +70,7 @@ protected InformerConfiguration(
7070
ItemStore<R> itemStore,
7171
Long informerListLimit,
7272
FieldSelector fieldSelector,
73-
boolean comparableResourceVersions,
73+
Boolean comparableResourceVersions,
7474
Duration obsoleteResourceCacheCheckInterval) {
7575
this(resourceClass);
7676
this.name = name;
@@ -319,6 +319,13 @@ public InformerConfiguration<R> buildForController() {
319319
}
320320
// to avoid potential NPE
321321
followControllerNamespaceChanges = false;
322+
if (comparableResourceVersions == null) {
323+
comparableResourceVersions = DEFAULT_COMPARABLE_RESOURCE_VERSION;
324+
}
325+
326+
if (obsoleteResourceCacheCheckInterval == null) {
327+
obsoleteResourceCacheCheckInterval = DEFAULT_OBSOLETE_RESOURCE_CHECK_INTERVAL;
328+
}
322329
return InformerConfiguration.this;
323330
}
324331

@@ -330,6 +337,14 @@ public InformerConfiguration<R> build() {
330337
if (followControllerNamespaceChanges == null) {
331338
followControllerNamespaceChanges = DEFAULT_FOLLOW_CONTROLLER_NAMESPACE_CHANGES;
332339
}
340+
if (comparableResourceVersions == null) {
341+
comparableResourceVersions = DEFAULT_COMPARABLE_RESOURCE_VERSION;
342+
}
343+
344+
if (obsoleteResourceCacheCheckInterval == null) {
345+
obsoleteResourceCacheCheckInterval = DEFAULT_OBSOLETE_RESOURCE_CHECK_INTERVAL;
346+
}
347+
333348
return InformerConfiguration.this;
334349
}
335350

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerEventSourceConfiguration.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;
3535
import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;
3636

37-
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSION;
38-
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_OBSOLETE_RESOURCE_CHECK_INTERVAL;
3937
import static io.javaoperatorsdk.operator.api.reconciler.Constants.SAME_AS_CONTROLLER_NAMESPACES_SET;
4038
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_ALL_NAMESPACE_SET;
4139
import static io.javaoperatorsdk.operator.api.reconciler.Constants.WATCH_CURRENT_NAMESPACE_SET;
@@ -92,35 +90,25 @@ default Optional<KubernetesClient> getKubernetesClient() {
9290
return Optional.empty();
9391
}
9492

95-
boolean comparableResourceVersion();
96-
97-
Duration getObsoleteResourceCacheCheckInterval();
98-
9993
class DefaultInformerEventSourceConfiguration<R extends HasMetadata>
10094
implements InformerEventSourceConfiguration<R> {
10195
private final PrimaryToSecondaryMapper<?> primaryToSecondaryMapper;
10296
private final SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
10397
private final GroupVersionKind groupVersionKind;
10498
private final InformerConfiguration<R> informerConfig;
10599
private final KubernetesClient kubernetesClient;
106-
private final boolean comparableResourceVersion;
107-
private final Duration obsoleteResourceCacheCheckInterval;
108100

109101
protected DefaultInformerEventSourceConfiguration(
110102
GroupVersionKind groupVersionKind,
111103
PrimaryToSecondaryMapper<?> primaryToSecondaryMapper,
112104
SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper,
113105
InformerConfiguration<R> informerConfig,
114-
KubernetesClient kubernetesClient,
115-
boolean comparableResourceVersion,
116-
Duration obsoleteResourceCacheCheckInterval) {
106+
KubernetesClient kubernetesClient) {
117107
this.informerConfig = Objects.requireNonNull(informerConfig);
118108
this.groupVersionKind = groupVersionKind;
119109
this.primaryToSecondaryMapper = primaryToSecondaryMapper;
120110
this.secondaryToPrimaryMapper = secondaryToPrimaryMapper;
121111
this.kubernetesClient = kubernetesClient;
122-
this.comparableResourceVersion = comparableResourceVersion;
123-
this.obsoleteResourceCacheCheckInterval = obsoleteResourceCacheCheckInterval;
124112
}
125113

126114
@Override
@@ -148,16 +136,6 @@ public Optional<GroupVersionKind> getGroupVersionKind() {
148136
public Optional<KubernetesClient> getKubernetesClient() {
149137
return Optional.ofNullable(kubernetesClient);
150138
}
151-
152-
@Override
153-
public boolean comparableResourceVersion() {
154-
return this.comparableResourceVersion;
155-
}
156-
157-
@Override
158-
public Duration getObsoleteResourceCacheCheckInterval() {
159-
return obsoleteResourceCacheCheckInterval;
160-
}
161139
}
162140

163141
@SuppressWarnings({"unused", "UnusedReturnValue"})
@@ -171,8 +149,6 @@ class Builder<R extends HasMetadata> {
171149
private PrimaryToSecondaryMapper<?> primaryToSecondaryMapper;
172150
private SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
173151
private KubernetesClient kubernetesClient;
174-
private boolean comparableResourceVersion = DEFAULT_COMPARABLE_RESOURCE_VERSION;
175-
private Duration obsoleteResourceCacheCheckInterval = DEFAULT_OBSOLETE_RESOURCE_CHECK_INTERVAL;
176152

177153
private Builder(Class<R> resourceClass, Class<? extends HasMetadata> primaryResourceClass) {
178154
this(resourceClass, primaryResourceClass, null);
@@ -311,13 +287,13 @@ public Builder<R> withFieldSelector(FieldSelector fieldSelector) {
311287
}
312288

313289
public Builder<R> withComparableResourceVersion(boolean comparableResourceVersion) {
314-
this.comparableResourceVersion = comparableResourceVersion;
290+
config.withComparableResourceVersions(comparableResourceVersion);
315291
return this;
316292
}
317293

318294
public Builder<R> withObsoleteResourceCacheCheckInterval(
319295
Duration obsoleteResourceCacheCheckInterval) {
320-
this.obsoleteResourceCacheCheckInterval = obsoleteResourceCacheCheckInterval;
296+
config.withObsoleteResourceCacheCheckInterval(obsoleteResourceCacheCheckInterval);
321297
return this;
322298
}
323299

@@ -360,9 +336,7 @@ public InformerEventSourceConfiguration<R> build() {
360336
HasMetadata.getKind(primaryResourceClass),
361337
false)),
362338
config.build(),
363-
kubernetesClient,
364-
comparableResourceVersion,
365-
obsoleteResourceCacheCheckInterval);
339+
kubernetesClient);
366340
}
367341
}
368342
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/controller/ControllerEventSource.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public class ControllerEventSource<T extends HasMetadata>
4848

4949
@SuppressWarnings({"unchecked", "rawtypes"})
5050
public ControllerEventSource(Controller<T> controller) {
51-
super(
52-
NAME,
53-
controller.getCRClient(),
54-
controller.getConfiguration(),
55-
controller.getConfiguration().getInformerConfig().isComparableResourceVersions());
51+
super(NAME, controller.getCRClient(), controller.getConfiguration());
5652
this.controller = controller;
5753

5854
final var config = controller.getConfiguration();

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
import io.javaoperatorsdk.operator.processing.event.source.ResourceAction;
3636
import io.javaoperatorsdk.operator.processing.event.source.informer.TemporaryResourceCache.EventHandling;
3737

38-
import static io.javaoperatorsdk.operator.api.reconciler.Constants.DEFAULT_COMPARABLE_RESOURCE_VERSION;
39-
4038
/**
4139
* Wraps informer(s) so they are connected to the eventing system of the framework. Note that since
4240
* this is built on top of Fabric8 client Informers, it also supports caching resources using
@@ -58,29 +56,18 @@ public class InformerEventSource<R extends HasMetadata, P extends HasMetadata>
5856

5957
public InformerEventSource(
6058
InformerEventSourceConfiguration<R> configuration, EventSourceContext<P> context) {
61-
this(
62-
configuration,
63-
configuration.getKubernetesClient().orElse(context.getClient()),
64-
configuration.comparableResourceVersion());
65-
}
66-
67-
InformerEventSource(InformerEventSourceConfiguration<R> configuration, KubernetesClient client) {
68-
this(configuration, client, DEFAULT_COMPARABLE_RESOURCE_VERSION);
59+
this(configuration, configuration.getKubernetesClient().orElse(context.getClient()));
6960
}
7061

7162
@SuppressWarnings({"unchecked", "rawtypes"})
72-
private InformerEventSource(
73-
InformerEventSourceConfiguration<R> configuration,
74-
KubernetesClient client,
75-
boolean comparableResourceVersions) {
63+
InformerEventSource(InformerEventSourceConfiguration<R> configuration, KubernetesClient client) {
7664
super(
7765
configuration.name(),
7866
configuration
7967
.getGroupVersionKind()
8068
.map(gvk -> client.genericKubernetesResources(gvk.apiVersion(), gvk.getKind()))
8169
.orElseGet(() -> (MixedOperation) client.resources(configuration.getResourceClass())),
82-
configuration,
83-
comparableResourceVersions);
70+
configuration);
8471
// If there is a primary to secondary mapper there is no need for primary to secondary index.
8572
primaryToSecondaryMapper = configuration.getPrimaryToSecondaryMapper();
8673
if (useSecondaryToPrimaryIndex()) {

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ public abstract class ManagedInformerEventSource<
6767
protected TemporaryResourceCache<R> temporaryResourceCache;
6868
protected MixedOperation client;
6969

70-
protected ManagedInformerEventSource(
71-
String name, MixedOperation client, C configuration, boolean comparableResourceVersions) {
70+
protected ManagedInformerEventSource(String name, MixedOperation client, C configuration) {
7271
super(configuration.getResourceClass(), name);
73-
this.comparableResourceVersions = comparableResourceVersions;
72+
this.comparableResourceVersions =
73+
configuration.getInformerConfig().isComparableResourceVersions();
7474
this.client = client;
7575
this.configuration = configuration;
7676
}

0 commit comments

Comments
 (0)