Skip to content

refactor: renaming core classes and APIs #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d478e35
refactor: renaming central classes and APIs
csviri Nov 2, 2021
3b76d5e
Merge branch 'v2' into renamings-reconciler
csviri Nov 2, 2021
5919eac
refactor!: moving reconciler related classes to reconciler package
csviri Nov 2, 2021
74920ab
refactor: moving reconciler and related classes to separate package
csviri Nov 2, 2021
3f92747
refactor!: further renamings
csviri Nov 4, 2021
fb58685
refactor!: renamed ConfiguredController to Controller
csviri Nov 4, 2021
55b859d
Merge branch 'v2' into renamings-reconciler
csviri Nov 4, 2021
6f07321
Merge branch 'v2' into renamings-reconciler
csviri Nov 4, 2021
444f7d1
fix: removed unused method
csviri Nov 4, 2021
8b1be24
refactor: reconcile and cleanup
csviri Nov 5, 2021
424f800
refactor: EventDispatcher to ReconciliationDispatcher
csviri Nov 5, 2021
adc543a
refactor: associated controller to reconciler
csviri Nov 5, 2021
1d148ac
fix: drawio pic
csviri Nov 8, 2021
9ec3471
refactor!: renaming @Controller to @ControllerAnnotation
csviri Nov 8, 2021
910293a
fix: controllerConfiguration refactor issues in docs
csviri Nov 8, 2021
349fc11
refactor: image consistent naming
csviri Nov 8, 2021
2e0ec8b
fix: cleanup IT
csviri Nov 9, 2021
75b8e0e
fix: fix imports
csviri Nov 9, 2021
8811dc3
fix: improvements
csviri Nov 9, 2021
224bcdf
fix: log message for crd apply in IT
csviri Nov 9, 2021
94980ee
fix: propagate cause to MissingCRD exception
csviri Nov 9, 2021
cadbc8a
fix: naming
csviri Nov 9, 2021
0f9eaba
fix: increased minikube version
csviri Nov 10, 2021
725fb06
fix: experiment with CR IT issue
csviri Nov 10, 2021
b51e69b
docs: comment on sleep
csviri Nov 10, 2021
0521f8e
fix: formatting
csviri Nov 10, 2021
4105def
refactor: rename ControllerAnnotationProcessor to ControllerConfigura…
metacosm Nov 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DECISION_LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

The original idea was to explicitly support retry in the scheduler. However, this turned out to complicate the algorithm
in case of event sources. Mostly it would be harder to manage the buffer, and the other event sources, thus what
does it mean for other event sources that there was a failed controller execution? Probably it would be better to
manage this in an abstract controller, and just use the "reprocess event-source" source in case of an error.
does it mean for other event sources that there was a failed controllerConfiguration execution? Probably it would be better to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you got too eager with search and replace :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intellij too intelligent :) will fix these

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but probably we can delete Decision log since it is not used

manage this in an abstract controllerConfiguration, and just use the "reprocess event-source" source in case of an error.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ dependencies {
```

Once you've added the dependency, define a main method initializing the Operator and registering a
controller.
controllerConfiguration.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.


```java
public class Runner {
Expand All @@ -146,7 +146,7 @@ The Controller implements the business logic and describes all the classes neede

```java

@Controller
@ControllerConfiguration
public class WebServerController implements ResourceController<WebServer> {

// Return the changed resource, so it gets updated. See javadoc for details.
Expand Down
10 changes: 5 additions & 5 deletions docs/documentation/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ other configuration options are provided to fine tune or turn off these features
## Controller Execution in a Nutshell

Controller execution is always triggered by an event. Events typically come from the custom resource
(i.e. custom resource is created, updated or deleted) that the controller is watching, but also from different sources
(i.e. custom resource is created, updated or deleted) that the controllerConfiguration is watching, but also from different sources
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

(see event sources). When an event is received reconciliation is executed, unless there is already a reconciliation
happening for a particular custom resource. In other words it is guaranteed by the framework that no concurrent
reconciliation happens for a custom resource.
Expand All @@ -24,7 +24,7 @@ i.e. [ResourceController](https://github.com/java-operator-sdk/java-operator-sdk
called, a post-processing phase follows, where typically framework checks if:

- an exception was thrown during execution, if yes schedules a retry.
- there are new events received during the controller execution, if yes schedule the execution again.
- there are new events received during the controllerConfiguration execution, if yes schedule the execution again.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

- there is an instruction to re-schedule the execution for the future, if yes schedule a timer event with the specified
delay.
- if none above, the reconciliation is finished.
Expand All @@ -45,14 +45,14 @@ Finalizers are automatically added by the framework as the first step, thus when
before the first reconciliation, the custom resource is updated via a Kubernetes API call. As a result of this update, the
finalizer will be present. The subsequent event will be received, which will trigger the first reconciliation.

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

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

This behavior can be turned off, so when configured no finalizer will be added or removed.
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)
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)
annotation for more details.

### When not to Use Finalizers?
Expand Down Expand Up @@ -90,7 +90,7 @@ time.
## Contextual Info for Logging with MDC

Logging is enhanced with additional contextual information using [MDC](http://www.slf4j.org/manual.html#mdc).
This following attributes are available in most parts of reconciliation logic and during the execution of the controller:
This following attributes are available in most parts of reconciliation logic and during the execution of the controllerConfiguration:

| MDC Key | Value added from Custom Resource |
| :--- | :--- |
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if the operator just gets restarted after it went down.

### At Least Once

To implement controller logic, we have to override two methods: `createOrUpdateResource` and `deleteResource`.
To implement controllerConfiguration logic, we have to override two methods: `createOrUpdateResource` and `deleteResource`.
These methods are called if a resource is created/changed or marked for deletion. In most cases these methods will be
called just once, but in some rare cases, it can happen that they are called more then once. In practice this means that the
implementation needs to be **idempotent**.
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/use-samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
```

Once you've added the dependency, define a main method initializing the Operator and registering a
controller.
controllerConfiguration.

```java
public class Runner {
Expand Down
4 changes: 4 additions & 0 deletions docs/etc/v1_model.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/etc/v2_model.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.Map;

import io.javaoperatorsdk.operator.api.RetryInfo;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
import io.javaoperatorsdk.operator.processing.event.Event;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.Locale;

import io.javaoperatorsdk.operator.api.Controller;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;

@SuppressWarnings("rawtypes")
public class ControllerUtils {
Expand All @@ -14,33 +14,32 @@ public static String getDefaultFinalizerName(String crdName) {
return crdName + FINALIZER_NAME_SUFFIX;
}

public static String getNameFor(Class<? extends ResourceController> controllerClass) {
public static String getNameFor(Class<? extends Reconciler> controllerClass) {
// if the controller annotation has a name attribute, use it
final var annotation = controllerClass.getAnnotation(Controller.class);
final var annotation = controllerClass.getAnnotation(ControllerConfiguration.class);
if (annotation != null) {
final var name = annotation.name();
if (!Controller.EMPTY_STRING.equals(name)) {
if (!ControllerConfiguration.EMPTY_STRING.equals(name)) {
return name;
}
}

// otherwise, use the lower-cased full class name
return getDefaultNameFor(controllerClass);
}

public static String getNameFor(ResourceController controller) {
public static String getNameFor(Reconciler controller) {
return getNameFor(controller.getClass());
}

public static String getDefaultNameFor(ResourceController controller) {
public static String getDefaultNameFor(Reconciler controller) {
return getDefaultNameFor(controller.getClass());
}

public static String getDefaultNameFor(Class<? extends ResourceController> controllerClass) {
return getDefaultResourceControllerName(controllerClass.getSimpleName());
public static String getDefaultNameFor(Class<? extends Reconciler> reconcilerClass) {
return getDefaultReconcilerName(reconcilerClass.getSimpleName());
}

public static String getDefaultResourceControllerName(String rcControllerClassName) {
public static String getDefaultReconcilerName(String rcControllerClassName) {
// if the name is fully qualified, extract the simple class name
final var lastDot = rcControllerClassName.lastIndexOf('.');
if (lastDot > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.Version;
import io.javaoperatorsdk.operator.api.LifecycleAware;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
import io.javaoperatorsdk.operator.processing.ConfiguredController;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.processing.Controller;

@SuppressWarnings("rawtypes")
public class Operator implements AutoCloseable, LifecycleAware {
Expand Down Expand Up @@ -49,7 +49,7 @@ public ConfigurationService getConfigurationService() {
return configurationService;
}

public List<ConfiguredController> getControllers() {
public List<Controller> getControllers() {
return new ArrayList<>(controllers.controllers.values());
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public void close() {
* @param <R> the {@code CustomResource} type associated with the controller
* @throws OperatorException if a problem occurred during the registration process
*/
public <R extends CustomResource<?, ?>> void register(ResourceController<R> controller)
public <R extends CustomResource<?, ?>> void register(Reconciler<R> controller)
throws OperatorException {
register(controller, null);
}
Expand All @@ -126,29 +126,29 @@ public void close() {
* passing it the controller's original configuration. The effective registration of the
* controller is delayed till the operator is started.
*
* @param controller the controller to register
* @param reconciler part of the controller to register
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we do this change, we need to remove the controller part completely everywhere and only talk about Reconciler because otherwiser it gets too confusing. Like what is a Controller is our SDK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered above, the controller. Reconciler is just the logic how to reconciler, but this is basically same in controller runtime, the controller is the whole , reconciler is just part of it.
Unfortunate that we don't have a class representing the controller itslef, Maybe to renamae ConfiguredController to Controller?

* @param configuration the configuration with which we want to register the controller, if {@code
* null}, the controller's original configuration is used
* @param <R> the {@code CustomResource} type associated with the controller
* @throws OperatorException if a problem occurred during the registration process
*/
public <R extends CustomResource<?, ?>> void register(
ResourceController<R> controller, ControllerConfiguration<R> configuration)
Reconciler<R> reconciler, ControllerConfiguration<R> configuration)
throws OperatorException {
final var existing = configurationService.getConfigurationFor(controller);
final var existing = configurationService.getConfigurationFor(reconciler);
if (existing == null) {
throw new OperatorException(
"Cannot register controller with name " + controller.getClass().getCanonicalName() +
" controller named " + ControllerUtils.getNameFor(controller)
"Cannot register controller with name " + reconciler.getClass().getCanonicalName() +
" controller named " + ControllerUtils.getNameFor(reconciler)
+ " because its configuration cannot be found.\n" +
" Known controllers are: " + configurationService.getKnownControllerNames());
} else {
if (configuration == null) {
configuration = existing;
}
final var configuredController =
new ConfiguredController<>(controller, configuration, kubernetesClient);
controllers.add(configuredController);
final var controller =
new Controller<>(reconciler, configuration, kubernetesClient);
controllers.add(controller);

final var watchedNS =
configuration.watchAllNamespaces()
Expand All @@ -163,7 +163,7 @@ public void close() {
}

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

public synchronized void shouldStart() {
Expand All @@ -176,7 +176,7 @@ public synchronized void shouldStart() {
}

public synchronized void start() {
controllers.values().parallelStream().forEach(ConfiguredController::start);
controllers.values().parallelStream().forEach(Controller::start);
started = true;
}

Expand All @@ -193,18 +193,18 @@ public synchronized void stop() {
started = false;
}

public synchronized void add(ConfiguredController configuredController) {
final var configuration = configuredController.getConfiguration();
public synchronized void add(Controller controller) {
final var configuration = controller.getConfiguration();
final var crdName = configuration.getCRDName();
final var existing = controllers.get(crdName);
if (existing != null) {
throw new OperatorException("Cannot register controller '" + configuration.getName()
+ "': another controller named '" + existing.getConfiguration().getName()
+ "' is already registered for CRD '" + crdName + "'");
}
this.controllers.put(crdName, configuredController);
this.controllers.put(crdName, controller);
if (started) {
configuredController.start();
controller.start();
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;

/**
* If the custom resource's status implements this interface, the observed generation will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;

@SuppressWarnings("rawtypes")
public class AbstractConfigurationService implements ConfigurationService {
Expand All @@ -32,7 +32,7 @@ public AbstractConfigurationService(Version version) {
if (failIfExisting) {
final var existing = configurations.get(name);
if (existing != null) {
throwExceptionOnNameCollision(config.getAssociatedControllerClassName(), existing);
throwExceptionOnNameCollision(config.getAssociatedReconcilerClassName(), existing);
}
}
configurations.put(name, config);
Expand All @@ -45,14 +45,14 @@ public AbstractConfigurationService(Version version) {
"Controller name '"
+ existing.getName()
+ "' is used by both "
+ existing.getAssociatedControllerClassName()
+ existing.getAssociatedReconcilerClassName()
+ " and "
+ newControllerClassName);
}

@Override
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
ResourceController<R> controller) {
Reconciler<R> controller) {
final var key = keyFor(controller);
final var configuration = configurations.get(key);
if (configuration == null) {
Expand All @@ -73,7 +73,7 @@ private String getControllersNameMessage() {
+ ".";
}

protected <R extends CustomResource<?, ?>> String keyFor(ResourceController<R> controller) {
protected <R extends CustomResource<?, ?>> String keyFor(Reconciler<R> controller) {
return ControllerUtils.getNameFor(controller);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;

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

/**
* Retrieves the Kubernetes client configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;

public class ConfigurationServiceOverrider {
private final ConfigurationService original;
Expand Down Expand Up @@ -62,7 +62,7 @@ public ConfigurationService build() {
return new ConfigurationService() {
@Override
public <R extends CustomResource<?, ?>> ControllerConfiguration<R> getConfigurationFor(
ResourceController<R> controller) {
Reconciler<R> controller) {
return original.getConfigurationFor(controller);
}

Expand Down
Loading