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/actions-setup-minikube@v2.4.2
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.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Optional;
44

55
import io.fabric8.kubernetes.client.CustomResource;
6+
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
67

78
/**
89
* If the custom resource's status implements this interface, the observed generation will be

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import io.fabric8.kubernetes.client.CustomResource;
99
import io.javaoperatorsdk.operator.ControllerUtils;
10-
import io.javaoperatorsdk.operator.api.ResourceController;
10+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
1111

1212
@SuppressWarnings("rawtypes")
1313
public class AbstractConfigurationService implements ConfigurationService {
@@ -32,7 +32,7 @@ public AbstractConfigurationService(Version version) {
3232
if (failIfExisting) {
3333
final var existing = configurations.get(name);
3434
if (existing != null) {
35-
throwExceptionOnNameCollision(config.getAssociatedControllerClassName(), existing);
35+
throwExceptionOnNameCollision(config.getAssociatedReconcilerClassName(), existing);
3636
}
3737
}
3838
configurations.put(name, config);
@@ -45,14 +45,14 @@ public AbstractConfigurationService(Version version) {
4545
"Controller name '"
4646
+ existing.getName()
4747
+ "' is used by both "
48-
+ existing.getAssociatedControllerClassName()
48+
+ existing.getAssociatedReconcilerClassName()
4949
+ " and "
5050
+ newControllerClassName);
5151
}
5252

5353
@Override
5454
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
55-
ResourceController<R> controller) {
55+
Reconciler<R> controller) {
5656
final var key = keyFor(controller);
5757
final var configuration = configurations.get(key);
5858
if (configuration == null) {
@@ -73,7 +73,7 @@ private String getControllersNameMessage() {
7373
+ ".";
7474
}
7575

76-
protected <R extends CustomResource<?, ?>> String keyFor(ResourceController<R> controller) {
76+
protected <R extends CustomResource<?, ?>> String keyFor(Reconciler<R> controller) {
7777
return ControllerUtils.getNameFor(controller);
7878
}
7979

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

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

77
import io.fabric8.kubernetes.client.Config;
88
import io.fabric8.kubernetes.client.CustomResource;
9-
import io.javaoperatorsdk.operator.api.ResourceController;
109
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
10+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
1111

1212
import com.fasterxml.jackson.core.JsonProcessingException;
1313
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -37,7 +37,7 @@ public interface ConfigurationService {
3737
* null} if no configuration exists for the controller
3838
*/
3939
<R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
40-
ResourceController<R> controller);
40+
Reconciler<R> controller);
4141

4242
/**
4343
* Retrieves the Kubernetes client configuration

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import io.fabric8.kubernetes.client.Config;
66
import io.fabric8.kubernetes.client.CustomResource;
7-
import io.javaoperatorsdk.operator.api.ResourceController;
87
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
8+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
99

1010
public class ConfigurationServiceOverrider {
1111
private final ConfigurationService original;
@@ -62,7 +62,7 @@ public ConfigurationService build() {
6262
return new ConfigurationService() {
6363
@Override
6464
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
65-
ResourceController<R> controller) {
65+
Reconciler<R> controller) {
6666
return original.getConfigurationFor(controller);
6767
}
6868

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

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

77
import io.fabric8.kubernetes.client.CustomResource;
88
import io.javaoperatorsdk.operator.ControllerUtils;
9-
import io.javaoperatorsdk.operator.api.Controller;
109
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilter;
1110
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilters;
1211

1312
public interface ControllerConfiguration<R extends CustomResource<?, ?>> {
1413

1514
default String getName() {
16-
return ControllerUtils.getDefaultResourceControllerName(getAssociatedControllerClassName());
15+
return ControllerUtils.getDefaultReconcilerName(getAssociatedReconcilerClassName());
1716
}
1817

1918
default String getCRDName() {
@@ -45,7 +44,7 @@ default Class<R> getCustomResourceClass() {
4544
return (Class<R>) type.getActualTypeArguments()[0];
4645
}
4746

48-
String getAssociatedControllerClassName();
47+
String getAssociatedReconcilerClassName();
4948

5049
default Set<String> getNamespaces() {
5150
return Collections.emptySet();
@@ -66,7 +65,8 @@ default boolean watchCurrentNamespace() {
6665
static boolean currentNamespaceWatched(Set<String> namespaces) {
6766
return namespaces != null
6867
&& namespaces.size() == 1
69-
&& namespaces.contains(Controller.WATCH_CURRENT_NAMESPACE);
68+
&& namespaces.contains(
69+
io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.WATCH_CURRENT_NAMESPACE);
7070
}
7171

7272
/**
@@ -98,7 +98,8 @@ default RetryConfiguration getRetryConfiguration() {
9898
default void setConfigurationService(ConfigurationService service) {}
9999

100100
default boolean useFinalizer() {
101-
return !Controller.NO_FINALIZER.equals(getFinalizer());
101+
return !io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.NO_FINALIZER
102+
.equals(getFinalizer());
102103
}
103104

104105
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public ControllerConfigurationOverrider<R> withCustomResourcePredicate(
7676

7777
public ControllerConfiguration<R> build() {
7878
return new DefaultControllerConfiguration<>(
79-
original.getAssociatedControllerClassName(),
79+
original.getAssociatedReconcilerClassName(),
8080
original.getName(),
8181
original.getCRDName(),
8282
finalizer,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public boolean isGenerationAware() {
7575
}
7676

7777
@Override
78-
public String getAssociatedControllerClassName() {
78+
public String getAssociatedReconcilerClassName() {
7979
return associatedControllerClassName;
8080
}
8181

0 commit comments

Comments
 (0)