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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.List;
import java.util.Map;

import io.javaoperatorsdk.operator.api.RetryInfo;
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
import io.javaoperatorsdk.operator.processing.event.Event;
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.Controller;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;

@SuppressWarnings("rawtypes")
public class ControllerUtils {
Expand All @@ -14,7 +14,7 @@ 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);
if (annotation != null) {
Expand All @@ -28,19 +28,19 @@ public static String getNameFor(Class<? extends ResourceController> controllerCl
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 getDefaultResourceReconcilerName(reconcilerClass.getSimpleName());
}

public static String getDefaultResourceControllerName(String rcControllerClassName) {
public static String getDefaultResourceReconcilerName(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,7 +14,7 @@
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.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.ExecutorServiceManager;
Expand Down Expand Up @@ -114,9 +114,9 @@ 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 registerController(Reconciler<R> controller)
throws OperatorException {
register(controller, null);
registerController(controller, null);
}

/**
Expand All @@ -126,28 +126,28 @@ 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)
public <R extends CustomResource<?, ?>> void registerController(
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);
new ConfiguredController<>(reconciler, configuration, kubernetesClient);
controllers.add(configuredController);

final var watchedNS =
Expand Down
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 Down Expand Up @@ -52,7 +52,7 @@ public AbstractConfigurationService(Version version) {

@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,7 +6,7 @@

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

import com.fasterxml.jackson.core.JsonProcessingException;
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,7 +4,7 @@

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

public class ConfigurationServiceOverrider {
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,14 @@

import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.Controller;
import io.javaoperatorsdk.operator.api.reconciler.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.getDefaultResourceReconcilerName(getAssociatedControllerClassName());
}

default String getCRDName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Map;

import io.javaoperatorsdk.operator.api.RetryInfo;
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
import io.javaoperatorsdk.operator.processing.event.Event;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

public class DeleteControl extends BaseControl<DeleteControl> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import io.fabric8.kubernetes.client.CustomResource;

public interface ResourceController<R extends CustomResource<?, ?>> {
public interface Reconciler<R extends CustomResource<?, ?>> {

/**
* Note that this method is used in combination of finalizers. If automatic finalizer handling is
Expand All @@ -28,7 +28,7 @@ public interface ResourceController<R extends CustomResource<?, ?>> {
* finalizer to indicate that the resource should not be deleted after all, in which case
* the controller should restore the resource's state appropriately.
*/
default DeleteControl deleteResource(R resource, Context context) {
default DeleteControl deleteResources(R resource, Context context) {
return DeleteControl.defaultDelete();
}

Expand All @@ -46,6 +46,6 @@ default DeleteControl deleteResource(R resource, Context context) {
* be skipped. <b>However we will always call an update if there is no finalizer on object
* and it's not marked for deletion.</b>
*/
UpdateControl<R> createOrUpdateResource(R resource, Context context);
UpdateControl<R> createOrUpdateResources(R resource, Context context);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

public interface RetryInfo {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.javaoperatorsdk.operator.api;
package io.javaoperatorsdk.operator.api.reconciler;

import io.fabric8.kubernetes.client.CustomResource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
import io.javaoperatorsdk.operator.CustomResourceUtils;
import io.javaoperatorsdk.operator.MissingCRDException;
import io.javaoperatorsdk.operator.OperatorException;
import io.javaoperatorsdk.operator.api.Context;
import io.javaoperatorsdk.operator.api.DeleteControl;
import io.javaoperatorsdk.operator.api.EventSourceInitializer;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceInitializer;
import io.javaoperatorsdk.operator.api.LifecycleAware;
import io.javaoperatorsdk.operator.api.ResourceController;
import io.javaoperatorsdk.operator.api.UpdateControl;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.monitoring.Metrics.ControllerExecution;
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;

public class ConfiguredController<R extends CustomResource<?, ?>> implements ResourceController<R>,
public class ConfiguredController<R extends CustomResource<?, ?>> implements Reconciler<R>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this class should be renamed ConfiguredReconciler or maybe simply Controller, where for our SDK a Controller would be a Reconciler associated with its configuration? In this case, we should also rename the Controller annotation to something different, maybe Configuration… Then again, the more I think about it, maybe we shouldn't be renaming things too much if there is no obvious benefit from doing so… because otherwise it will mean that we confuse our existing users and we will need to update all our existing documentation / articles…

Copy link
Collaborator Author

@csviri csviri Nov 4, 2021

Choose a reason for hiding this comment

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

hehe, yes also wrote this above , maybe this should be the Controller, and the @Controller annotation should be @ControllerConfiguration.

I think this class should be our high level aggregate (therefore name it as Controller), so it will contiain the Reconciler, the EventSourceManager, the EventProcessor (former DefaultEventHandler). Basically every aspect of a single controller instance.

The benefit is that we are now closer to go terminology, but on the other hand yes it can be confusing for the users. But getting it right now for v2 is probably the good time to do it "once and for all" :)

LifecycleAware, EventSourceInitializer<R> {
private final ResourceController<R> controller;
private final Reconciler<R> reconciler;
private final ControllerConfiguration<R> configuration;
private final KubernetesClient kubernetesClient;
private DefaultEventSourceManager<R> eventSourceManager;

public ConfiguredController(ResourceController<R> controller,
public ConfiguredController(Reconciler<R> reconciler,
ControllerConfiguration<R> configuration,
KubernetesClient kubernetesClient) {
this.controller = controller;
this.reconciler = reconciler;
this.configuration = configuration;
this.kubernetesClient = kubernetesClient;
}

@Override
public DeleteControl deleteResource(R resource, Context context) {
public DeleteControl deleteResources(R resource, Context context) {
return configuration.getConfigurationService().getMetrics().timeControllerExecution(
new ControllerExecution<>() {
@Override
Expand All @@ -58,13 +58,13 @@ public String successTypeName(DeleteControl deleteControl) {

@Override
public DeleteControl execute() {
return controller.deleteResource(resource, context);
return reconciler.deleteResources(resource, context);
}
});
}

@Override
public UpdateControl<R> createOrUpdateResource(R resource, Context context) {
public UpdateControl<R> createOrUpdateResources(R resource, Context context) {
return configuration.getConfigurationService().getMetrics().timeControllerExecution(
new ControllerExecution<>() {
@Override
Expand All @@ -91,7 +91,7 @@ public String successTypeName(UpdateControl<R> result) {

@Override
public UpdateControl<R> execute() {
return controller.createOrUpdateResource(resource, context);
return reconciler.createOrUpdateResources(resource, context);
}
});
}
Expand Down Expand Up @@ -124,8 +124,8 @@ public String toString() {
return "'" + configuration.getName() + "' Controller";
}

public ResourceController<R> getController() {
return controller;
public Reconciler<R> getReconciler() {
return reconciler;
}

public ControllerConfiguration<R> getConfiguration() {
Expand Down Expand Up @@ -169,8 +169,8 @@ public void start() throws OperatorException {

try {
eventSourceManager = new DefaultEventSourceManager<>(this);
if (controller instanceof EventSourceInitializer) {
((EventSourceInitializer<R>) controller).prepareEventSources(eventSourceManager);
if (reconciler instanceof EventSourceInitializer) {
((EventSourceInitializer<R>) reconciler).prepareEventSources(eventSourceManager);
}
} catch (MissingCRDException e) {
throwMissingCRDException(crdName, specVersion, controllerName);
Expand Down
Loading