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 all 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
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Set up Minikube
uses: manusa/[email protected]
with:
minikube version: 'v1.22.0'
minikube version: 'v1.24.0'
kubernetes version: ${{ matrix.kubernetes }}
driver: 'docker'
- name: Run integration tests
Expand Down
12 changes: 0 additions & 12 deletions DECISION_LOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/documentation/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.drawio.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
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.Controller;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilters;

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

default String getName() {
return ControllerUtils.getDefaultResourceControllerName(getAssociatedControllerClassName());
return ControllerUtils.getDefaultReconcilerName(getAssociatedReconcilerClassName());
}

default String getCRDName() {
Expand Down Expand Up @@ -45,7 +44,7 @@ default Class<R> getCustomResourceClass() {
return (Class<R>) type.getActualTypeArguments()[0];
}

String getAssociatedControllerClassName();
String getAssociatedReconcilerClassName();

default Set<String> getNamespaces() {
return Collections.emptySet();
Expand All @@ -66,7 +65,8 @@ default boolean watchCurrentNamespace() {
static boolean currentNamespaceWatched(Set<String> namespaces) {
return namespaces != null
&& namespaces.size() == 1
&& namespaces.contains(Controller.WATCH_CURRENT_NAMESPACE);
&& namespaces.contains(
io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.WATCH_CURRENT_NAMESPACE);
}

/**
Expand Down Expand Up @@ -98,7 +98,8 @@ default RetryConfiguration getRetryConfiguration() {
default void setConfigurationService(ConfigurationService service) {}

default boolean useFinalizer() {
return !Controller.NO_FINALIZER.equals(getFinalizer());
return !io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration.NO_FINALIZER
.equals(getFinalizer());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ControllerConfigurationOverrider<R> withCustomResourcePredicate(

public ControllerConfiguration<R> build() {
return new DefaultControllerConfiguration<>(
original.getAssociatedControllerClassName(),
original.getAssociatedReconcilerClassName(),
original.getName(),
original.getCRDName(),
finalizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean isGenerationAware() {
}

@Override
public String getAssociatedControllerClassName() {
public String getAssociatedReconcilerClassName() {
return associatedControllerClassName;
}

Expand Down
Loading