Skip to content

Commit d7bb14c

Browse files
committed
refactor: use DefaultResourceConfiguration for controller configuration
1 parent 3986343 commit d7bb14c

File tree

2 files changed

+7
-39
lines changed

2 files changed

+7
-39
lines changed

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

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@
88
import io.javaoperatorsdk.operator.processing.event.source.controller.ResourceEventFilter;
99

1010
public class DefaultControllerConfiguration<R extends HasMetadata>
11+
extends DefaultResourceConfiguration<R>
1112
implements ControllerConfiguration<R> {
1213

1314
private final String associatedControllerClassName;
1415
private final String name;
1516
private final String crdName;
1617
private final String finalizer;
1718
private final boolean generationAware;
18-
private final Set<String> namespaces;
19-
private final boolean watchAllNamespaces;
2019
private final RetryConfiguration retryConfiguration;
21-
private final String labelSelector;
2220
private final ResourceEventFilter<R> resourceEventFilter;
23-
private final Class<R> resourceClass;
2421
private final List<DependentResource> dependents;
25-
private ConfigurationService service;
2622

2723
// NOSONAR constructor is meant to provide all information
2824
public DefaultControllerConfiguration(
@@ -38,23 +34,18 @@ public DefaultControllerConfiguration(
3834
Class<R> resourceClass,
3935
ConfigurationService service,
4036
List<DependentResource> dependents) {
37+
super(labelSelector, resourceClass, namespaces);
4138
this.associatedControllerClassName = associatedControllerClassName;
4239
this.name = name;
4340
this.crdName = crdName;
4441
this.finalizer = finalizer;
4542
this.generationAware = generationAware;
46-
this.namespaces =
47-
namespaces != null ? Collections.unmodifiableSet(namespaces) : Collections.emptySet();
48-
this.watchAllNamespaces = this.namespaces.isEmpty();
4943
this.retryConfiguration =
5044
retryConfiguration == null
5145
? ControllerConfiguration.super.getRetryConfiguration()
5246
: retryConfiguration;
53-
this.labelSelector = labelSelector;
5447
this.resourceEventFilter = resourceEventFilter;
55-
this.resourceClass =
56-
resourceClass == null ? ControllerConfiguration.super.getResourceClass()
57-
: resourceClass;
48+
5849
setConfigurationService(service);
5950
this.dependents = dependents != null ? dependents : Collections.emptyList();
6051
}
@@ -84,43 +75,19 @@ public String getAssociatedReconcilerClassName() {
8475
return associatedControllerClassName;
8576
}
8677

87-
@Override
88-
public Set<String> getNamespaces() {
89-
return namespaces;
90-
}
91-
92-
@Override
93-
public boolean watchAllNamespaces() {
94-
return watchAllNamespaces;
95-
}
96-
9778
@Override
9879
public RetryConfiguration getRetryConfiguration() {
9980
return retryConfiguration;
10081
}
10182

102-
@Override
103-
public ConfigurationService getConfigurationService() {
104-
return service;
105-
}
10683

10784
@Override
10885
public void setConfigurationService(ConfigurationService service) {
109-
if (this.service != null) {
86+
if (getConfigurationService() != null) {
11087
throw new IllegalStateException("A ConfigurationService is already associated with '" + name
11188
+ "' ControllerConfiguration. Cannot change it once set!");
11289
}
113-
this.service = service;
114-
}
115-
116-
@Override
117-
public String getLabelSelector() {
118-
return labelSelector;
119-
}
120-
121-
@Override
122-
public Class<R> getResourceClass() {
123-
return resourceClass;
90+
super.setConfigurationService(service);
12491
}
12592

12693
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public DefaultResourceConfiguration(String labelSelector, Class<R> resourceClass
2323
public DefaultResourceConfiguration(String labelSelector, Class<R> resourceClass,
2424
Set<String> namespaces) {
2525
this.labelSelector = labelSelector;
26-
this.resourceClass = resourceClass;
26+
this.resourceClass = resourceClass == null ? ResourceConfiguration.super.getResourceClass()
27+
: resourceClass;
2728
this.namespaces = namespaces != null ? namespaces : Collections.emptySet();
2829
this.watchAllNamespaces = this.namespaces.isEmpty();
2930
}

0 commit comments

Comments
 (0)