Skip to content

Commit 97cdcb7

Browse files
authored
fix: simplify informer config generics (operator-framework#1184)
1 parent cace2be commit 97cdcb7

File tree

8 files changed

+19
-24
lines changed

8 files changed

+19
-24
lines changed

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

+9-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io.fabric8.kubernetes.api.model.HasMetadata;
88
import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration;
99
import io.javaoperatorsdk.operator.api.config.ResourceConfiguration;
10-
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
1110
import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper;
1211
import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;
1312

@@ -40,7 +39,7 @@ public SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
4039
SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper();
4140

4241
@SuppressWarnings("unused")
43-
class InformerConfigurationBuilder<R extends HasMetadata, P extends HasMetadata> {
42+
class InformerConfigurationBuilder<R extends HasMetadata> {
4443

4544
private SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
4645
private Set<String> namespaces;
@@ -51,24 +50,24 @@ private InformerConfigurationBuilder(Class<R> resourceClass) {
5150
this.resourceClass = resourceClass;
5251
}
5352

54-
public InformerConfigurationBuilder<R, P> withSecondaryToPrimaryMapper(
53+
public InformerConfigurationBuilder<R> withSecondaryToPrimaryMapper(
5554
SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper) {
5655
this.secondaryToPrimaryMapper = secondaryToPrimaryMapper;
5756
return this;
5857
}
5958

60-
public InformerConfigurationBuilder<R, P> withNamespaces(String... namespaces) {
59+
public InformerConfigurationBuilder<R> withNamespaces(String... namespaces) {
6160
this.namespaces = namespaces != null ? Set.of(namespaces) : Collections.emptySet();
6261
return this;
6362
}
6463

65-
public InformerConfigurationBuilder<R, P> withNamespaces(Set<String> namespaces) {
64+
public InformerConfigurationBuilder<R> withNamespaces(Set<String> namespaces) {
6665
this.namespaces = namespaces != null ? namespaces : Collections.emptySet();
6766
return this;
6867
}
6968

7069

71-
public InformerConfigurationBuilder<R, P> withLabelSelector(String labelSelector) {
70+
public InformerConfigurationBuilder<R> withLabelSelector(String labelSelector) {
7271
this.labelSelector = labelSelector;
7372
return this;
7473
}
@@ -80,19 +79,15 @@ public InformerConfiguration<R> build() {
8079
}
8180
}
8281

83-
static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuilder<R, P> from(
84-
EventSourceContext<P> context, Class<R> resourceClass) {
82+
static <R extends HasMetadata> InformerConfigurationBuilder<R> from(
83+
Class<R> resourceClass) {
8584
return new InformerConfigurationBuilder<>(resourceClass);
8685
}
8786

88-
@SuppressWarnings({"rawtypes", "unchecked"})
89-
static InformerConfigurationBuilder from(Class resourceClass) {
90-
return new InformerConfigurationBuilder<>(resourceClass);
91-
}
9287

93-
static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuilder<R, P> from(
88+
static <R extends HasMetadata> InformerConfigurationBuilder<R> from(
9489
InformerConfiguration<R> configuration) {
95-
return new InformerConfigurationBuilder<R, P>(configuration.getResourceClass())
90+
return new InformerConfigurationBuilder<R>(configuration.getResourceClass())
9691
.withNamespaces(configuration.getNamespaces())
9792
.withLabelSelector(configuration.getLabelSelector())
9893
.withSecondaryToPrimaryMapper(configuration.getSecondaryToPrimaryMapper());

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void configureWith(KubernetesDependentResourceConfig config) {
5454

5555
@SuppressWarnings("unchecked")
5656
private void configureWith(String labelSelector, Set<String> namespaces) {
57-
final var primaryResourcesRetriever =
57+
final SecondaryToPrimaryMapper<R> primaryResourcesRetriever =
5858
(this instanceof SecondaryToPrimaryMapper) ? (SecondaryToPrimaryMapper<R>) this
5959
: Mappers.fromOwnerReference();
6060
InformerConfiguration<R> ic =

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/createupdateeventfilter/CreateUpdateEventFilterTestReconciler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso
102102
public Map<String, EventSource> prepareEventSources(
103103
EventSourceContext<CreateUpdateEventFilterTestCustomResource> context) {
104104
InformerConfiguration<ConfigMap> informerConfiguration =
105-
InformerConfiguration.from(context, ConfigMap.class)
105+
InformerConfiguration.from(ConfigMap.class)
106106
.withLabelSelector("integrationtest = " + this.getClass().getSimpleName())
107107
.build();
108108
informerEventSource = new InformerEventSource<>(informerConfiguration, client);

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/informereventsource/InformerEventSourceTestCustomReconciler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Map<String, EventSource> prepareEventSources(
4242
EventSourceContext<InformerEventSourceTestCustomResource> context) {
4343

4444
InformerConfiguration<ConfigMap> config =
45-
InformerConfiguration.from(context, ConfigMap.class)
45+
InformerConfiguration.from(ConfigMap.class)
4646
.withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME))
4747
.build();
4848

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/multiplesecondaryeventsource/MultipleSecondaryEventSourceReconciler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Map<String, EventSource> prepareEventSources(
6666
EventSourceContext<MultipleSecondaryEventSourceCustomResource> context) {
6767

6868

69-
var config = InformerConfiguration.from(context, ConfigMap.class)
69+
var config = InformerConfiguration.from(ConfigMap.class)
7070
.withNamespaces(context.getControllerConfiguration().getNamespaces())
7171
.withLabelSelector("multisecondary")
7272
.withSecondaryToPrimaryMapper(s -> {

operator-framework/src/test/java/io/javaoperatorsdk/operator/sample/primaryindexer/PrimaryIndexerTestReconciler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Map<String, EventSource> prepareEventSources(
2424
context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer);
2525

2626
var informerConfiguration =
27-
InformerConfiguration.from(context, ConfigMap.class)
27+
InformerConfiguration.from(ConfigMap.class)
2828
.withSecondaryToPrimaryMapper(
2929
(ConfigMap secondaryResource) -> context
3030
.getPrimaryCache()

sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Map<String, EventSource> prepareEventSources(EventSourceContext<Webapp> c
5959
.collect(Collectors.toSet());
6060

6161
InformerConfiguration<Tomcat> configuration =
62-
InformerConfiguration.from(context, Tomcat.class)
62+
InformerConfiguration.from(Tomcat.class)
6363
.withSecondaryToPrimaryMapper(webappsMatchingTomcatName)
6464
.build();
6565
return EventSourceInitializer

sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ public WebPageReconciler(KubernetesClient kubernetesClient) {
5151
@Override
5252
public Map<String, EventSource> prepareEventSources(EventSourceContext<WebPage> context) {
5353
var configMapEventSource =
54-
new InformerEventSource<>(InformerConfiguration.from(context, ConfigMap.class)
54+
new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class)
5555
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
5656
.build(), context);
5757
var deploymentEventSource =
58-
new InformerEventSource<>(InformerConfiguration.from(context, Deployment.class)
58+
new InformerEventSource<>(InformerConfiguration.from(Deployment.class)
5959
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
6060
.build(), context);
6161
var serviceEventSource =
62-
new InformerEventSource<>(InformerConfiguration.from(context, Service.class)
62+
new InformerEventSource<>(InformerConfiguration.from(Service.class)
6363
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
6464
.build(), context);
6565
var ingressEventSource =
66-
new InformerEventSource<>(InformerConfiguration.from(context, Ingress.class)
66+
new InformerEventSource<>(InformerConfiguration.from(Ingress.class)
6767
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
6868
.build(), context);
6969
return EventSourceInitializer.nameEventSources(configMapEventSource, deploymentEventSource,

0 commit comments

Comments
 (0)