Skip to content

Commit b8669c8

Browse files
authored
refactor: more controller -> reconciler renaming (#750)
1 parent 29fe326 commit b8669c8

File tree

17 files changed

+109
-115
lines changed

17 files changed

+109
-115
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ public void close() {
107107
}
108108

109109
/**
110-
* Add a registration requests for the specified controller with this operator. The effective
111-
* registration of the controller is delayed till the operator is started.
110+
* Add a registration requests for the specified reconciler with this operator. The effective
111+
* registration of the reconciler is delayed till the operator is started.
112112
*
113-
* @param reconciler the controller to register
114-
* @param <R> the {@code CustomResource} type associated with the controller
113+
* @param reconciler the reconciler to register
114+
* @param <R> the {@code CustomResource} type associated with the reconciler
115115
* @throws OperatorException if a problem occurred during the registration process
116116
*/
117117
public <R extends HasMetadata> void register(Reconciler<R> reconciler)
@@ -121,15 +121,15 @@ public <R extends HasMetadata> void register(Reconciler<R> reconciler)
121121
}
122122

123123
/**
124-
* Add a registration requests for the specified controller with this operator, overriding its
124+
* Add a registration requests for the specified reconciler with this operator, overriding its
125125
* default configuration by the specified one (usually created via
126126
* {@link io.javaoperatorsdk.operator.api.config.ControllerConfigurationOverrider#override(ControllerConfiguration)},
127-
* passing it the controller's original configuration. The effective registration of the
128-
* controller is delayed till the operator is started.
127+
* passing it the reconciler's original configuration. The effective registration of the
128+
* reconciler is delayed till the operator is started.
129129
*
130-
* @param reconciler part of the controller to register
131-
* @param configuration the configuration with which we want to register the controller
132-
* @param <R> the {@code CustomResource} type associated with the controller
130+
* @param reconciler part of the reconciler to register
131+
* @param configuration the configuration with which we want to register the reconciler
132+
* @param <R> the {@code CustomResource} type associated with the reconciler
133133
* @throws OperatorException if a problem occurred during the registration process
134134
*/
135135
public <R extends HasMetadata> void register(Reconciler<R> reconciler,
@@ -138,10 +138,10 @@ public <R extends HasMetadata> void register(Reconciler<R> reconciler,
138138

139139
if (configuration == null) {
140140
throw new OperatorException(
141-
"Cannot register controller with name " + reconciler.getClass().getCanonicalName() +
142-
" controller named " + ControllerUtils.getNameFor(reconciler)
141+
"Cannot register reconciler with name " + reconciler.getClass().getCanonicalName() +
142+
" reconciler named " + ReconcilerUtils.getNameFor(reconciler)
143143
+ " because its configuration cannot be found.\n" +
144-
" Known controllers are: " + configurationService.getKnownControllerNames());
144+
" Known reconcilers are: " + configurationService.getKnownReconcilerNames());
145145
}
146146

147147
final var controller = new Controller<>(reconciler, configuration, kubernetesClient);
@@ -152,7 +152,7 @@ public <R extends HasMetadata> void register(Reconciler<R> reconciler,
152152
: configuration.getEffectiveNamespaces();
153153

154154
log.info(
155-
"Registered Controller: '{}' for CRD: '{}' for namespace(s): {}",
155+
"Registered reconciler: '{}' for resource: '{}' for namespace(s): {}",
156156
configuration.getName(),
157157
configuration.getResourceClass(),
158158
watchedNS);
@@ -191,14 +191,14 @@ public synchronized void stop() {
191191

192192
public synchronized void add(Controller controller) {
193193
final var configuration = controller.getConfiguration();
194-
final var crdName = configuration.getResourceTypeName();
195-
final var existing = controllers.get(crdName);
194+
final var resourceTypeName = configuration.getResourceTypeName();
195+
final var existing = controllers.get(resourceTypeName);
196196
if (existing != null) {
197197
throw new OperatorException("Cannot register controller '" + configuration.getName()
198198
+ "': another controller named '" + existing.getConfiguration().getName()
199-
+ "' is already registered for CRD '" + crdName + "'");
199+
+ "' is already registered for resource '" + resourceTypeName + "'");
200200
}
201-
this.controllers.put(crdName, controller);
201+
this.controllers.put(resourceTypeName, controller);
202202
if (started) {
203203
controller.start();
204204
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java renamed to operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ReconcilerUtils.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@
66
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
77

88
@SuppressWarnings("rawtypes")
9-
public class ControllerUtils {
9+
public class ReconcilerUtils {
1010

1111
private static final String FINALIZER_NAME_SUFFIX = "/finalizer";
1212

1313
public static String getDefaultFinalizerName(String crdName) {
1414
return crdName + FINALIZER_NAME_SUFFIX;
1515
}
1616

17-
public static String getNameFor(Class<? extends Reconciler> controllerClass) {
18-
// if the controller annotation has a name attribute, use it
19-
final var annotation = controllerClass.getAnnotation(ControllerConfiguration.class);
17+
public static String getNameFor(Class<? extends Reconciler> reconcilerClass) {
18+
// if the reconciler annotation has a name attribute, use it
19+
final var annotation = reconcilerClass.getAnnotation(ControllerConfiguration.class);
2020
if (annotation != null) {
2121
final var name = annotation.name();
2222
if (!ControllerConfiguration.EMPTY_STRING.equals(name)) {
2323
return name;
2424
}
2525
}
2626
// otherwise, use the lower-cased full class name
27-
return getDefaultNameFor(controllerClass);
27+
return getDefaultNameFor(reconcilerClass);
2828
}
2929

30-
public static String getNameFor(Reconciler controller) {
31-
return getNameFor(controller.getClass());
30+
public static String getNameFor(Reconciler reconciler) {
31+
return getNameFor(reconciler.getClass());
3232
}
3333

34-
public static String getDefaultNameFor(Reconciler controller) {
35-
return getDefaultNameFor(controller.getClass());
34+
public static String getDefaultNameFor(Reconciler reconciler) {
35+
return getDefaultNameFor(reconciler.getClass());
3636
}
3737

3838
public static String getDefaultNameFor(Class<? extends Reconciler> reconcilerClass) {
3939
return getDefaultReconcilerName(reconcilerClass.getSimpleName());
4040
}
4141

42-
public static String getDefaultReconcilerName(String rcControllerClassName) {
42+
public static String getDefaultReconcilerName(String reconcilerClassName) {
4343
// if the name is fully qualified, extract the simple class name
44-
final var lastDot = rcControllerClassName.lastIndexOf('.');
44+
final var lastDot = reconcilerClassName.lastIndexOf('.');
4545
if (lastDot > 0) {
46-
rcControllerClassName = rcControllerClassName.substring(lastDot + 1);
46+
reconcilerClassName = reconcilerClassName.substring(lastDot + 1);
4747
}
48-
return rcControllerClassName.toLowerCase(Locale.ROOT);
48+
return reconcilerClassName.toLowerCase(Locale.ROOT);
4949
}
5050
}

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.stream.Stream;
77

88
import io.fabric8.kubernetes.api.model.HasMetadata;
9-
import io.javaoperatorsdk.operator.ControllerUtils;
9+
import io.javaoperatorsdk.operator.ReconcilerUtils;
1010
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
1111

1212
@SuppressWarnings("rawtypes")
@@ -40,53 +40,52 @@ private <R extends HasMetadata> void put(
4040
}
4141

4242
protected <R extends HasMetadata> void throwExceptionOnNameCollision(
43-
String newControllerClassName, ControllerConfiguration<R> existing) {
43+
String newReconcilerClassName, ControllerConfiguration<R> existing) {
4444
throw new IllegalArgumentException(
45-
"Controller name '"
45+
"Reconciler name '"
4646
+ existing.getName()
4747
+ "' is used by both "
4848
+ existing.getAssociatedReconcilerClassName()
4949
+ " and "
50-
+ newControllerClassName);
50+
+ newReconcilerClassName);
5151
}
5252

5353
@Override
5454
public <R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(
55-
Reconciler<R> controller) {
56-
final var key = keyFor(controller);
55+
Reconciler<R> reconciler) {
56+
final var key = keyFor(reconciler);
5757
final var configuration = configurations.get(key);
5858
if (configuration == null) {
59-
logMissingControllerWarning(key, getControllersNameMessage());
59+
logMissingReconcilerWarning(key, getReconcilersNameMessage());
6060
}
6161
return configuration;
6262
}
6363

64-
protected void logMissingControllerWarning(String controllerKey,
65-
String controllersNameMessage) {
64+
protected void logMissingReconcilerWarning(String reconcilerKey, String reconcilersNameMessage) {
6665
System.out
67-
.println("Cannot find controller named '" + controllerKey + "'. " + controllersNameMessage);
66+
.println("Cannot find reconciler named '" + reconcilerKey + "'. " + reconcilersNameMessage);
6867
}
6968

70-
private String getControllersNameMessage() {
71-
return "Known controllers: "
72-
+ getKnownControllerNames().stream().reduce((s, s2) -> s + ", " + s2).orElse("None")
69+
private String getReconcilersNameMessage() {
70+
return "Known reconcilers: "
71+
+ getKnownReconcilerNames().stream().reduce((s, s2) -> s + ", " + s2).orElse("None")
7372
+ ".";
7473
}
7574

76-
protected <R extends HasMetadata> String keyFor(Reconciler<R> controller) {
77-
return ControllerUtils.getNameFor(controller);
75+
protected <R extends HasMetadata> String keyFor(Reconciler<R> reconciler) {
76+
return ReconcilerUtils.getNameFor(reconciler);
7877
}
7978

80-
protected ControllerConfiguration getFor(String controllerName) {
81-
return configurations.get(controllerName);
79+
protected ControllerConfiguration getFor(String reconcilerName) {
80+
return configurations.get(reconcilerName);
8281
}
8382

8483
protected Stream<ControllerConfiguration> controllerConfigurations() {
8584
return configurations.values().stream();
8685
}
8786

8887
@Override
89-
public Set<String> getKnownControllerNames() {
88+
public Set<String> getKnownReconcilerNames() {
9089
return configurations.keySet();
9190
}
9291

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public BaseConfigurationService(Version version) {
1313
}
1414

1515
@Override
16-
protected void logMissingControllerWarning(String controllerKey, String controllersNameMessage) {
17-
logger.warn("Configuration for controller '{}' was not found. {}", controllerKey,
18-
controllersNameMessage);
16+
protected void logMissingReconcilerWarning(String reconcilerKey, String reconcilersNameMessage) {
17+
logger.warn("Configuration for reconciler '{}' was not found. {}", reconcilerKey,
18+
reconcilersNameMessage);
1919
}
2020

2121
public String getLoggerName() {

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ public HasMetadata clone(HasMetadata object) {
3030
};
3131

3232
/**
33-
* Retrieves the configuration associated with the specified controller
33+
* Retrieves the configuration associated with the specified reconciler
3434
*
35-
* @param controller the controller we want the configuration of
36-
* @param <R> the {@code CustomResource} type associated with the specified controller
37-
* @return the {@link ControllerConfiguration} associated with the specified controller or {@code
38-
* null} if no configuration exists for the controller
35+
* @param reconciler the reconciler we want the configuration of
36+
* @param <R> the {@code CustomResource} type associated with the specified reconciler
37+
* @return the {@link ControllerConfiguration} associated with the specified reconciler or {@code
38+
* null} if no configuration exists for the reconciler
3939
*/
40-
<R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(
41-
Reconciler<R> controller);
40+
<R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(Reconciler<R> reconciler);
4241

4342
/**
4443
* Retrieves the Kubernetes client configuration
@@ -51,11 +50,11 @@ default Config getClientConfiguration() {
5150
}
5251

5352
/**
54-
* Retrieves the set of the names of controllers for which a configuration exists
53+
* Retrieves the set of the names of reconcilers for which a configuration exists
5554
*
56-
* @return the set of known controller names
55+
* @return the set of known reconciler names
5756
*/
58-
Set<String> getKnownControllerNames();
57+
Set<String> getKnownReconcilerNames();
5958

6059
/**
6160
* Retrieves the {@link Version} information associated with this particular instance of the SDK
@@ -67,7 +66,7 @@ default Config getClientConfiguration() {
6766
/**
6867
* Whether the operator should query the CRD to make sure it's deployed and validate
6968
* {@link CustomResource} implementations before attempting to register the associated
70-
* controllers.
69+
* reconcilers.
7170
*
7271
* <p>
7372
* Note that this might require elevating the privileges associated with the operator to gain read
@@ -83,7 +82,7 @@ default boolean checkCRDAndValidateLocalModel() {
8382

8483
/**
8584
* Retrieves the maximum number of threads the operator can spin out to dispatch reconciliation
86-
* requests to controllers
85+
* requests to reconcilers
8786
*
8887
* @return the maximum number of concurrent reconciliation threads
8988
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public ConfigurationService build() {
6262
return new ConfigurationService() {
6363
@Override
6464
public <R extends HasMetadata> ControllerConfiguration<R> getConfigurationFor(
65-
Reconciler<R> controller) {
66-
return original.getConfigurationFor(controller);
65+
Reconciler<R> reconciler) {
66+
return original.getConfigurationFor(reconciler);
6767
}
6868

6969
@Override
70-
public Set<String> getKnownControllerNames() {
71-
return original.getKnownControllerNames();
70+
public Set<String> getKnownReconcilerNames() {
71+
return original.getKnownReconcilerNames();
7272
}
7373

7474
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
import io.fabric8.kubernetes.api.model.HasMetadata;
88
import io.fabric8.kubernetes.client.CustomResource;
9-
import io.javaoperatorsdk.operator.ControllerUtils;
9+
import io.javaoperatorsdk.operator.ReconcilerUtils;
1010
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventFilter;
1111
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventFilters;
1212

1313
public interface ControllerConfiguration<R extends HasMetadata> {
1414

1515
default String getName() {
16-
return ControllerUtils.getDefaultReconcilerName(getAssociatedReconcilerClassName());
16+
return ReconcilerUtils.getDefaultReconcilerName(getAssociatedReconcilerClassName());
1717
}
1818

1919
default String getResourceTypeName() {
2020
return CustomResource.getCRDName(getResourceClass());
2121
}
2222

2323
default String getFinalizer() {
24-
return ControllerUtils.getDefaultFinalizerName(getResourceTypeName());
24+
return ReconcilerUtils.getDefaultFinalizerName(getResourceTypeName());
2525
}
2626

2727
/**

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ public interface Metrics {
1111

1212
default void receivedEvent(Event event) {}
1313

14-
default void reconcileCustomResource(ResourceID resourceID,
15-
RetryInfo retryInfo) {}
14+
default void reconcileCustomResource(ResourceID resourceID, RetryInfo retryInfo) {}
1615

17-
default void failedReconciliation(ResourceID resourceID,
18-
RuntimeException exception) {}
16+
default void failedReconciliation(ResourceID resourceID, RuntimeException exception) {}
1917

2018
default void cleanupDoneFor(ResourceID customResourceUid) {}
2119

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ControllerUtilsTest.java renamed to operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ReconcilerUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
import static org.junit.jupiter.api.Assertions.assertEquals;
88

9-
class ControllerUtilsTest {
9+
class ReconcilerUtilsTest {
1010

1111
@Test
1212
void getDefaultResourceControllerName() {
1313
assertEquals(
1414
"testcustomreconciler",
15-
ControllerUtils.getDefaultReconcilerName(
15+
ReconcilerUtils.getDefaultReconcilerName(
1616
TestCustomReconciler.class.getCanonicalName()));
1717
}
1818
}

0 commit comments

Comments
 (0)