Skip to content

Commit 86245ca

Browse files
authored
refactor: renaming core classes and APIs (#646)
Renaming and refactoring structures based on the rational described in #655
1 parent 0563e0e commit 86245ca

File tree

83 files changed

+839
-809
lines changed

Some content is hidden

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

83 files changed

+839
-809
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Set up Minikube
3636
uses: manusa/[email protected]
3737
with:
38-
minikube version: 'v1.22.0'
38+
minikube version: 'v1.24.0'
3939
kubernetes version: ${{ matrix.kubernetes }}
4040
driver: 'docker'
4141
- name: Run integration tests

DECISION_LOG.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The Controller implements the business logic and describes all the classes neede
146146

147147
```java
148148

149-
@Controller
149+
@ControllerConfiguration
150150
public class WebServerController implements ResourceController<WebServer> {
151151

152152
// Return the changed resource, so it gets updated. See javadoc for details.

docs/documentation/features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ Finalizers are automatically added by the framework as the first step, thus when
4545
before the first reconciliation, the custom resource is updated via a Kubernetes API call. As a result of this update, the
4646
finalizer will be present. The subsequent event will be received, which will trigger the first reconciliation.
4747

48-
The finalizer that is automatically added will be also removed after the `deleteResource` is executed on the controller.
48+
The finalizer that is automatically added will be also removed after the `deleteResource` is executed on the controllerConfiguration.
4949
However, the removal behavior can be further customized, and can be instructed to "not remove yet" - this is useful just
5050
in some specific corner cases, when there would be a long waiting period for some dependent resource cleanup.
5151

5252
The name of the finalizers can be specified, in case it is not, a name will be generated.
5353

5454
This behavior can be turned off, so when configured no finalizer will be added or removed.
55-
See [`@Controller`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java)
55+
See [`@ControllerConfiguration`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ControllerConfiguration.java)
5656
annotation for more details.
5757

5858
### When not to Use Finalizers?

docs/etc/v1_model.drawio.svg

Lines changed: 4 additions & 0 deletions
Loading

docs/etc/v2_model.drawio.svg

Lines changed: 4 additions & 0 deletions
Loading

micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.util.List;
66
import java.util.Map;
77

8-
import io.javaoperatorsdk.operator.api.RetryInfo;
98
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
9+
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
1010
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
1111
import io.javaoperatorsdk.operator.processing.event.Event;
1212
import io.micrometer.core.instrument.MeterRegistry;

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.util.Locale;
44

5-
import io.javaoperatorsdk.operator.api.Controller;
6-
import io.javaoperatorsdk.operator.api.ResourceController;
5+
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
6+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
77

88
@SuppressWarnings("rawtypes")
99
public class ControllerUtils {
@@ -14,33 +14,32 @@ public static String getDefaultFinalizerName(String crdName) {
1414
return crdName + FINALIZER_NAME_SUFFIX;
1515
}
1616

17-
public static String getNameFor(Class<? extends ResourceController> controllerClass) {
17+
public static String getNameFor(Class<? extends Reconciler> controllerClass) {
1818
// if the controller annotation has a name attribute, use it
19-
final var annotation = controllerClass.getAnnotation(Controller.class);
19+
final var annotation = controllerClass.getAnnotation(ControllerConfiguration.class);
2020
if (annotation != null) {
2121
final var name = annotation.name();
22-
if (!Controller.EMPTY_STRING.equals(name)) {
22+
if (!ControllerConfiguration.EMPTY_STRING.equals(name)) {
2323
return name;
2424
}
2525
}
26-
2726
// otherwise, use the lower-cased full class name
2827
return getDefaultNameFor(controllerClass);
2928
}
3029

31-
public static String getNameFor(ResourceController controller) {
30+
public static String getNameFor(Reconciler controller) {
3231
return getNameFor(controller.getClass());
3332
}
3433

35-
public static String getDefaultNameFor(ResourceController controller) {
34+
public static String getDefaultNameFor(Reconciler controller) {
3635
return getDefaultNameFor(controller.getClass());
3736
}
3837

39-
public static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) {
40-
return getDefaultResourceControllerName(controllerClass.getSimpleName());
38+
public static String getDefaultNameFor(Class<? extends Reconciler> reconcilerClass) {
39+
return getDefaultReconcilerName(reconcilerClass.getSimpleName());
4140
}
4241

43-
public static String getDefaultResourceControllerName(String rcControllerClassName) {
42+
public static String getDefaultReconcilerName(String rcControllerClassName) {
4443
// if the name is fully qualified, extract the simple class name
4544
final var lastDot = rcControllerClassName.lastIndexOf('.');
4645
if (lastDot > 0) {

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
@@ -14,11 +14,11 @@
1414
import io.fabric8.kubernetes.client.KubernetesClient;
1515
import io.fabric8.kubernetes.client.Version;
1616
import io.javaoperatorsdk.operator.api.LifecycleAware;
17-
import io.javaoperatorsdk.operator.api.ResourceController;
1817
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
1918
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
2019
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
21-
import io.javaoperatorsdk.operator.processing.ConfiguredController;
20+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
21+
import io.javaoperatorsdk.operator.processing.Controller;
2222

2323
@SuppressWarnings("rawtypes")
2424
public class Operator implements AutoCloseable, LifecycleAware {
@@ -49,7 +49,7 @@ public ConfigurationService getConfigurationService() {
4949
return configurationService;
5050
}
5151

52-
public List<ConfiguredController> getControllers() {
52+
public List<Controller> getControllers() {
5353
return new ArrayList<>(controllers.controllers.values());
5454
}
5555

@@ -114,7 +114,7 @@ public void close() {
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(ResourceController<R> controller)
117+
public <R extends CustomResource<?, ?>> void register(Reconciler<R> controller)
118118
throws OperatorException {
119119
register(controller, null);
120120
}
@@ -126,29 +126,29 @@ public void close() {
126126
* passing it the controller's original configuration. The effective registration of the
127127
* controller is delayed till the operator is started.
128128
*
129-
* @param controller the controller to register
129+
* @param reconciler part of the controller to register
130130
* @param configuration the configuration with which we want to register the controller, if {@code
131131
* null}, the controller's original configuration is used
132132
* @param <R> the {@code CustomResource} type associated with the controller
133133
* @throws OperatorException if a problem occurred during the registration process
134134
*/
135135
public <R extends CustomResource<?, ?>> void register(
136-
ResourceController<R> controller, ControllerConfiguration<R> configuration)
136+
Reconciler<R> reconciler, ControllerConfiguration<R> configuration)
137137
throws OperatorException {
138-
final var existing = configurationService.getConfigurationFor(controller);
138+
final var existing = configurationService.getConfigurationFor(reconciler);
139139
if (existing == null) {
140140
throw new OperatorException(
141-
"Cannot register controller with name " + controller.getClass().getCanonicalName() +
142-
" controller named " + ControllerUtils.getNameFor(controller)
141+
"Cannot register controller with name " + reconciler.getClass().getCanonicalName() +
142+
" controller named " + ControllerUtils.getNameFor(reconciler)
143143
+ " because its configuration cannot be found.\n" +
144144
" Known controllers are: " + configurationService.getKnownControllerNames());
145145
} else {
146146
if (configuration == null) {
147147
configuration = existing;
148148
}
149-
final var configuredController =
150-
new ConfiguredController<>(controller, configuration, kubernetesClient);
151-
controllers.add(configuredController);
149+
final var controller =
150+
new Controller<>(reconciler, configuration, kubernetesClient);
151+
controllers.add(controller);
152152

153153
final var watchedNS =
154154
configuration.watchAllNamespaces()
@@ -163,7 +163,7 @@ public void close() {
163163
}
164164

165165
static class ControllerManager implements LifecycleAware {
166-
private final Map<String, ConfiguredController> controllers = new HashMap<>();
166+
private final Map<String, Controller> controllers = new HashMap<>();
167167
private boolean started = false;
168168

169169
public synchronized void shouldStart() {
@@ -176,7 +176,7 @@ public synchronized void shouldStart() {
176176
}
177177

178178
public synchronized void start() {
179-
controllers.values().parallelStream().forEach(ConfiguredController::start);
179+
controllers.values().parallelStream().forEach(Controller::start);
180180
started = true;
181181
}
182182

@@ -193,18 +193,18 @@ public synchronized void stop() {
193193
started = false;
194194
}
195195

196-
public synchronized void add(ConfiguredController configuredController) {
197-
final var configuration = configuredController.getConfiguration();
196+
public synchronized void add(Controller controller) {
197+
final var configuration = controller.getConfiguration();
198198
final var crdName = configuration.getCRDName();
199199
final var existing = controllers.get(crdName);
200200
if (existing != null) {
201201
throw new OperatorException("Cannot register controller '" + configuration.getName()
202202
+ "': another controller named '" + existing.getConfiguration().getName()
203203
+ "' is already registered for CRD '" + crdName + "'");
204204
}
205-
this.controllers.put(crdName, configuredController);
205+
this.controllers.put(crdName, controller);
206206
if (started) {
207-
configuredController.start();
207+
controller.start();
208208
}
209209
}
210210
}

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)