Skip to content

Commit a6621c2

Browse files
metacosmcsviri
andauthored
refactor: clean up informer configuration classes (#2470)
* chore: set version to 5.0.0-SNAPSHOT (#2200) Signed-off-by: Attila Mészáros <[email protected]> * improve: replace current formatting plugins with spotless plugin (#2302) Signed-off-by: Attila Mészáros <[email protected]> * fix: format after rebase Signed-off-by: Attila Mészáros <[email protected]> * bump: chore use slf4j v2 (#2406) Signed-off-by: Attila Mészáros <[email protected]> * feat: allow returning additional information from conditions (#2426) Fixes #2424. --------- Signed-off-by: Attila Mészáros <[email protected]> Signed-off-by: Chris Laprun <[email protected]> Co-authored-by: Attila Mészáros <[email protected]> Signed-off-by: Chris Laprun <[email protected]> * refactor: move @InformerConfig to more appropriate package Signed-off-by: Chris Laprun <[email protected]> * refactor: move InformerConfigHolder to appropriate package Signed-off-by: Chris Laprun <[email protected]> * chore: remove unneeded code & dependencies Signed-off-by: Chris Laprun <[email protected]> * refactor: InformerConfiguration to InformerEventSourceConfiguration Signed-off-by: Chris Laprun <[email protected]> * refactor: rename inner InformerConfigurationBuilder to simply Builder Signed-off-by: Chris Laprun <[email protected]> * refactor: rename InformerConfig and associated field to Informer Signed-off-by: Chris Laprun <[email protected]> * refactor: rename InformerConfigHolder to InformerConfiguration Signed-off-by: Chris Laprun <[email protected]> --------- Signed-off-by: Attila Mészáros <[email protected]> Signed-off-by: Chris Laprun <[email protected]> Co-authored-by: Attila Mészáros <[email protected]>
1 parent 02b876b commit a6621c2

File tree

75 files changed

+673
-652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+673
-652
lines changed

bootstrapper-maven-plugin/src/main/resources/templates/Reconciler.java

-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
package {{groupId}};
22

3-
import io.fabric8.kubernetes.api.model.ConfigMap;
4-
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
5-
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
6-
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
73
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
84
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
95
import io.javaoperatorsdk.operator.api.reconciler.Context;
10-
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
11-
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
126
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
137
import io.javaoperatorsdk.operator.api.reconciler.Workflow;
14-
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
15-
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;
168

179
import java.util.Map;
1810
import java.util.Optional;
1911

2012
@Workflow(dependents = {@Dependent(type = ConfigMapDependentResource.class)})
21-
@ControllerConfiguration
2213
public class {{artifactClassId}}Reconciler implements Reconciler<{{artifactClassId}}CustomResource> {
2314

2415
public UpdateControl<{{artifactClassId}}CustomResource> reconcile({{artifactClassId}}CustomResource primary,

caffeine-bounded-cache-support/src/test/java/io/javaoperatorsdk/operator/processing/event/source/cache/sample/AbstractTestReconciler.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import io.fabric8.kubernetes.client.CustomResource;
1515
import io.fabric8.kubernetes.client.KubernetesClient;
1616
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
17-
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
17+
import io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration;
1818
import io.javaoperatorsdk.operator.api.reconciler.*;
1919
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
2020
import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore;
@@ -77,12 +77,14 @@ public List<EventSource<?, P>> prepareEventSources(
7777
boundedItemStore(new KubernetesClientBuilder().build(),
7878
ConfigMap.class, Duration.ofMinutes(1), 1); // setting max size for testing purposes
7979

80-
var es = new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class, primaryClass())
81-
.withInformerConfiguration(c -> c.withItemStore(boundedItemStore))
82-
.withSecondaryToPrimaryMapper(
83-
Mappers.fromOwnerReferences(context.getPrimaryResourceClass(),
84-
this instanceof BoundedCacheClusterScopeTestReconciler))
85-
.build(), context);
80+
var es = new InformerEventSource<>(
81+
InformerEventSourceConfiguration.from(ConfigMap.class, primaryClass())
82+
.withInformerConfiguration(c -> c.withItemStore(boundedItemStore))
83+
.withSecondaryToPrimaryMapper(
84+
Mappers.fromOwnerReferences(context.getPrimaryResourceClass(),
85+
this instanceof BoundedCacheClusterScopeTestReconciler))
86+
.build(),
87+
context);
8688

8789
return List.of(es);
8890
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import io.javaoperatorsdk.operator.api.config.Utils.Configurator;
1818
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceConfigurationResolver;
1919
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
20+
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
2021
import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec;
2122
import io.javaoperatorsdk.operator.api.reconciler.Constants;
2223
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
2324
import io.javaoperatorsdk.operator.api.reconciler.Workflow;
2425
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
2526
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
26-
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
2727
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
2828
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
2929
import io.javaoperatorsdk.operator.processing.retry.Retry;
@@ -275,8 +275,8 @@ private <P extends HasMetadata> ResolvedControllerConfiguration<P> controllerCon
275275
fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name
276276
: fieldManager;
277277

278-
InformerConfigHolder<P> informerConfig = InformerConfigHolder.builder(resourceClass)
279-
.initFromAnnotation(annotation != null ? annotation.informerConfig() : null, context)
278+
InformerConfiguration<P> informerConfig = InformerConfiguration.builder(resourceClass)
279+
.initFromAnnotation(annotation != null ? annotation.informer() : null, context)
280280
.buildForController();
281281

282282
return new ResolvedControllerConfiguration<P>(

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import io.fabric8.kubernetes.api.model.HasMetadata;
1111
import io.fabric8.kubernetes.client.informers.cache.ItemStore;
1212
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
13-
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
13+
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
1414
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
1515
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
1616
import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter;
@@ -30,12 +30,12 @@ public class ControllerConfigurationOverrider<R extends HasMetadata> {
3030
private String fieldManager;
3131
private Duration reconciliationMaxInterval;
3232
private Map<DependentResourceSpec, Object> configurations;
33-
private final InformerConfigHolder<R>.Builder config;
33+
private final InformerConfiguration<R>.Builder config;
3434

3535
private ControllerConfigurationOverrider(ControllerConfiguration<R> original) {
3636
this.finalizer = original.getFinalizerName();
3737
this.generationAware = original.isGenerationAware();
38-
this.config = InformerConfigHolder.builder(original.getResourceClass())
38+
this.config = InformerConfiguration.builder(original.getResourceClass())
3939
.withName(name)
4040
.withNamespaces(original.getNamespaces())
4141
.withLabelSelector(original.getLabelSelector())

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
55
import io.fabric8.kubernetes.api.model.HasMetadata;
66
import io.javaoperatorsdk.operator.ReconcilerUtils;
7-
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
7+
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
88

99
public class DefaultResourceConfiguration<R extends HasMetadata>
1010
implements ResourceConfiguration<R> {
1111

1212
private final Class<R> resourceClass;
1313
private final String resourceTypeName;
14-
private final InformerConfigHolder<R> informerConfig;
14+
private final InformerConfiguration<R> informerConfig;
1515

1616
protected DefaultResourceConfiguration(Class<R> resourceClass,
17-
InformerConfigHolder<R> informerConfig) {
17+
InformerConfiguration<R> informerConfig) {
1818
this.resourceClass = resourceClass;
1919
this.resourceTypeName = resourceClass.isAssignableFrom(GenericKubernetesResource.class)
2020
// in general this is irrelevant now for secondary resources it is used just by controller
@@ -35,7 +35,7 @@ public Class<R> getResourceClass() {
3535
}
3636

3737
@Override
38-
public InformerConfigHolder<R> getInformerConfig() {
38+
public InformerConfiguration<R> getInformerConfig() {
3939
return informerConfig;
4040
}
4141
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
import io.fabric8.kubernetes.api.model.HasMetadata;
1010
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
11+
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
1112
import io.javaoperatorsdk.operator.api.config.workflow.WorkflowSpec;
1213
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
13-
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
1414
import io.javaoperatorsdk.operator.processing.event.rate.RateLimiter;
1515
import io.javaoperatorsdk.operator.processing.retry.Retry;
1616

@@ -49,7 +49,7 @@ public ResolvedControllerConfiguration(Class<P> resourceClass, String name,
4949
Map<DependentResourceSpec, Object> configurations,
5050
String fieldManager,
5151
ConfigurationService configurationService,
52-
InformerConfigHolder<P> informerConfig,
52+
InformerConfiguration<P> informerConfig,
5353
WorkflowSpec workflowSpec) {
5454
this(resourceClass, name, generationAware, associatedReconcilerClassName, retry, rateLimiter,
5555
maxReconciliationInterval, finalizer, configurations, fieldManager,
@@ -62,7 +62,7 @@ protected ResolvedControllerConfiguration(Class<P> resourceClass, String name,
6262
RateLimiter rateLimiter, Duration maxReconciliationInterval, String finalizer,
6363
Map<DependentResourceSpec, Object> configurations,
6464
String fieldManager,
65-
ConfigurationService configurationService, InformerConfigHolder<P> informerConfig) {
65+
ConfigurationService configurationService, InformerConfiguration<P> informerConfig) {
6666
super(resourceClass, informerConfig);
6767
this.configurationService = configurationService;
6868
this.name = ControllerConfiguration.ensureValidName(name, associatedReconcilerClassName);
@@ -81,7 +81,7 @@ protected ResolvedControllerConfiguration(Class<P> resourceClass, String name,
8181
Class<? extends Reconciler> reconcilerClas, ConfigurationService configurationService) {
8282
this(resourceClass, name, false, getAssociatedReconcilerClassName(reconcilerClas), null, null,
8383
null, null, null, null, configurationService,
84-
InformerConfigHolder.builder(resourceClass).buildForController());
84+
InformerConfiguration.builder(resourceClass).buildForController());
8585
}
8686

8787
public static Duration getMaxReconciliationInterval(long interval, TimeUnit timeUnit) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import io.fabric8.kubernetes.client.informers.cache.ItemStore;
1111
import io.javaoperatorsdk.operator.OperatorException;
1212
import io.javaoperatorsdk.operator.ReconcilerUtils;
13+
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
1314
import io.javaoperatorsdk.operator.api.reconciler.Constants;
14-
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.InformerConfigHolder;
1515
import io.javaoperatorsdk.operator.processing.event.source.cache.BoundedItemStore;
1616
import io.javaoperatorsdk.operator.processing.event.source.filter.GenericFilter;
1717
import io.javaoperatorsdk.operator.processing.event.source.filter.OnAddFilter;
@@ -26,7 +26,7 @@ default String getResourceTypeName() {
2626
return ReconcilerUtils.getResourceTypeName(getResourceClass());
2727
}
2828

29-
InformerConfigHolder<R> getInformerConfig();
29+
InformerConfiguration<R> getInformerConfig();
3030

3131
default Optional<OnAddFilter<? super R>> onAddFilter() {
3232
return Optional.ofNullable(getInformerConfig().getOnAddFilter());
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.javaoperatorsdk.operator.processing.dependent.kubernetes;
1+
package io.javaoperatorsdk.operator.api.config.informer;
22

33
import java.lang.annotation.ElementType;
44
import java.lang.annotation.Retention;
@@ -13,13 +13,13 @@
1313
import io.javaoperatorsdk.operator.processing.event.source.filter.OnDeleteFilter;
1414
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;
1515

16-
import static io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE;
16+
import static io.javaoperatorsdk.operator.api.config.informer.InformerEventSourceConfiguration.DEFAULT_FOLLOW_CONTROLLER_NAMESPACES_ON_CHANGE;
1717
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_LONG_VALUE_SET;
1818
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET;
1919

2020
@Retention(RetentionPolicy.RUNTIME)
2121
@Target({ElementType.TYPE})
22-
public @interface InformerConfig {
22+
public @interface Informer {
2323

2424
String name() default NO_VALUE_SET;
2525

0 commit comments

Comments
 (0)