Skip to content

Commit 6ba73e7

Browse files
committed
refactor: refactored Operator.register api
1 parent 9bf803f commit 6ba73e7

File tree

1 file changed

+22
-26
lines changed
  • operator-framework-core/src/main/java/io/javaoperatorsdk/operator

1 file changed

+22
-26
lines changed

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

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ public void close() {
110110
* Add a registration requests for the specified controller with this operator. The effective
111111
* registration of the controller is delayed till the operator is started.
112112
*
113-
* @param controller the controller to register
113+
* @param reconciler the controller to register
114114
* @param <R> the {@code CustomResource} type associated with the controller
115115
* @throws OperatorException if a problem occurred during the registration process
116116
*/
117-
public <R extends CustomResource<?, ?>> void register(Reconciler<R> controller)
117+
public <R extends CustomResource<?, ?>> void register(Reconciler<R> reconciler)
118118
throws OperatorException {
119-
register(controller, null);
119+
final var defaultConfiguration = configurationService.getConfigurationFor(reconciler);
120+
register(reconciler, defaultConfiguration);
120121
}
121122

122123
/**
@@ -127,39 +128,34 @@ public void close() {
127128
* controller is delayed till the operator is started.
128129
*
129130
* @param reconciler part of the controller to register
130-
* @param configuration the configuration with which we want to register the controller, if {@code
131-
* null}, the controller's original configuration is used
131+
* @param configuration the configuration with which we want to register the controller
132132
* @param <R> the {@code CustomResource} type associated with the controller
133133
* @throws OperatorException if a problem occurred during the registration process
134134
*/
135-
public <R extends CustomResource<?, ?>> void register(
136-
Reconciler<R> reconciler, ControllerConfiguration<R> configuration)
135+
public <R extends CustomResource<?, ?>> void register(Reconciler<R> reconciler,
136+
ControllerConfiguration<R> configuration)
137137
throws OperatorException {
138-
final var existing = configurationService.getConfigurationFor(reconciler);
139-
if (existing == null) {
138+
139+
if (configuration == null) {
140140
throw new OperatorException(
141141
"Cannot register controller with name " + reconciler.getClass().getCanonicalName() +
142142
" controller named " + ControllerUtils.getNameFor(reconciler)
143143
+ " because its configuration cannot be found.\n" +
144144
" Known controllers are: " + configurationService.getKnownControllerNames());
145-
} else {
146-
if (configuration == null) {
147-
configuration = existing;
148-
}
149-
final var controller =
150-
new Controller<>(reconciler, configuration, kubernetesClient);
151-
controllers.add(controller);
152-
153-
final var watchedNS =
154-
configuration.watchAllNamespaces()
155-
? "[all namespaces]"
156-
: configuration.getEffectiveNamespaces();
157-
log.info(
158-
"Registered Controller: '{}' for CRD: '{}' for namespace(s): {}",
159-
configuration.getName(),
160-
configuration.getCustomResourceClass(),
161-
watchedNS);
162145
}
146+
147+
final var controller = new Controller<>(reconciler, configuration, kubernetesClient);
148+
149+
controllers.add(controller);
150+
151+
final var watchedNS =
152+
configuration.watchAllNamespaces() ? "[all namespaces]" : configuration.getEffectiveNamespaces();
153+
154+
log.info(
155+
"Registered Controller: '{}' for CRD: '{}' for namespace(s): {}",
156+
configuration.getName(),
157+
configuration.getCustomResourceClass(),
158+
watchedNS);
163159
}
164160

165161
static class ControllerManager implements LifecycleAware {

0 commit comments

Comments
 (0)