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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Locale;

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

@SuppressWarnings("rawtypes")
Expand All @@ -16,10 +16,10 @@ public static String getDefaultFinalizerName(String crdName) {

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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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

Expand Down Expand Up @@ -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 @@ -9,7 +9,7 @@

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Controller {
public @interface ControllerConfiguration {

String EMPTY_STRING = "";
String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.javaoperatorsdk.operator.Operator;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.config.Version;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
Expand Down Expand Up @@ -145,7 +144,9 @@ public TestCustomResource newMyResource(String app, String namespace) {
return resource;
}

public static class MyConfiguration implements ControllerConfiguration<TestCustomResource> {
public static class MyConfiguration
implements
io.javaoperatorsdk.operator.api.config.ControllerConfiguration<TestCustomResource> {

private final String labelSelector;
private final ConfigurationService service;
Expand Down Expand Up @@ -176,7 +177,7 @@ public ConfigurationService getConfigurationService() {
}
}

@Controller(namespaces = NAMESPACE)
@ControllerConfiguration(namespaces = NAMESPACE)
public static class MyController implements Reconciler<TestCustomResource> {

private final Consumer<TestCustomResource> consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.javaoperatorsdk.operator.sample.simple;

import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;

@Controller
@ControllerConfiguration
public class DuplicateCRController implements Reconciler<TestCustomResource> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.api.reconciler.*;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;

@Controller(generationAwareEventProcessing = false)
@ControllerConfiguration(generationAwareEventProcessing = false)
public class TestCustomReconciler implements Reconciler<TestCustomResource> {

private static final Logger log = LoggerFactory.getLogger(TestCustomReconciler.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.javaoperatorsdk.operator.sample.simple;

import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;

@Controller
@ControllerConfiguration
public class TestCustomReconcilerV2 implements Reconciler<TestCustomResourceV2> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@
import io.fabric8.kubernetes.client.CustomResource;
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilter;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventFilters;

public class AnnotationConfiguration<R extends CustomResource<?, ?>>
implements ControllerConfiguration<R> {
implements io.javaoperatorsdk.operator.api.config.ControllerConfiguration<R> {

private final Reconciler<R> controller;
private final Controller annotation;
private final Reconciler<R> reconciler;
private final ControllerConfiguration annotation;
private ConfigurationService service;

public AnnotationConfiguration(Reconciler<R> controller) {
this.controller = controller;
this.annotation = controller.getClass().getAnnotation(Controller.class);
public AnnotationConfiguration(Reconciler<R> reconciler) {
this.reconciler = reconciler;
this.annotation = reconciler.getClass().getAnnotation(ControllerConfiguration.class);
}

@Override
public String getName() {
return ControllerUtils.getNameFor(controller);
return ControllerUtils.getNameFor(reconciler);
}

@Override
Expand All @@ -40,22 +39,23 @@ public String getFinalizer() {

@Override
public boolean isGenerationAware() {
return valueOrDefault(annotation, Controller::generationAwareEventProcessing, true);
return valueOrDefault(annotation, ControllerConfiguration::generationAwareEventProcessing,
true);
}

@Override
public Class<R> getCustomResourceClass() {
return RuntimeControllerMetadata.getCustomResourceClass(controller);
return RuntimeControllerMetadata.getCustomResourceClass(reconciler);
}

@Override
public Set<String> getNamespaces() {
return Set.of(valueOrDefault(annotation, Controller::namespaces, new String[] {}));
return Set.of(valueOrDefault(annotation, ControllerConfiguration::namespaces, new String[] {}));
}

@Override
public String getLabelSelector() {
return valueOrDefault(annotation, Controller::labelSelector, "");
return valueOrDefault(annotation, ControllerConfiguration::labelSelector, "");
}

@Override
Expand All @@ -70,7 +70,7 @@ public void setConfigurationService(ConfigurationService service) {

@Override
public String getAssociatedReconcilerClassName() {
return controller.getClass().getCanonicalName();
return reconciler.getClass().getCanonicalName();
}

@SuppressWarnings("unchecked")
Expand All @@ -79,7 +79,8 @@ public CustomResourceEventFilter<R> getEventFilter() {
CustomResourceEventFilter<R> answer = null;

Class<CustomResourceEventFilter<R>>[] filterTypes =
(Class<CustomResourceEventFilter<R>>[]) valueOrDefault(annotation, Controller::eventFilters,
(Class<CustomResourceEventFilter<R>>[]) valueOrDefault(annotation,
ControllerConfiguration::eventFilters,
new Object[] {});
if (filterTypes.length > 0) {
for (var filterType : filterTypes) {
Expand All @@ -101,12 +102,13 @@ public CustomResourceEventFilter<R> getEventFilter() {
: CustomResourceEventFilters.passthrough();
}

public static <T> T valueOrDefault(Controller controller, Function<Controller, T> mapper,
public static <T> T valueOrDefault(ControllerConfiguration controllerConfiguration,
Function<ControllerConfiguration, T> mapper,
T defaultValue) {
if (controller == null) {
if (controllerConfiguration == null) {
return defaultValue;
} else {
return mapper.apply(controller);
return mapper.apply(controllerConfiguration);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import static io.javaoperatorsdk.operator.config.runtime.RuntimeControllerMetadata.RECONCILERS_RESOURCE_PATH;

@SupportedAnnotationTypes("io.javaoperatorsdk.operator.api.reconciler.Controller")
@SupportedAnnotationTypes("io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration")
@SupportedSourceVersion(SourceVersion.RELEASE_11)
@AutoService(Processor.class)
public class ControllerAnnotationProcessor extends AbstractProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.fabric8.kubernetes.model.annotation.Version;
import io.javaoperatorsdk.operator.ControllerUtils;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;

Expand Down Expand Up @@ -77,7 +77,8 @@ public void returnsValuesFromControllerAnnotationFinalizer() {
final var reconciler = new TestCustomReconciler();
final var configuration =
DefaultConfigurationService.instance().getConfigurationFor(reconciler);
assertEquals(CustomResource.getCRDName(TestCustomResource.class), configuration.getCRDName());
assertEquals(CustomResource.getCRDName(TestCustomResource.class),
configuration.getCRDName());
assertEquals(
ControllerUtils.getDefaultFinalizerName(configuration.getCRDName()),
configuration.getFinalizer());
Expand All @@ -104,7 +105,7 @@ public void supportsInnerClassCustomResources() {
});
}

@Controller(finalizerName = CUSTOM_FINALIZER_NAME)
@ControllerConfiguration(finalizerName = CUSTOM_FINALIZER_NAME)
static class TestCustomFinalizerReconciler
implements Reconciler<TestCustomFinalizerReconciler.InnerCustomResource> {

Expand All @@ -120,7 +121,7 @@ public static class InnerCustomResource extends CustomResource<Void, Void> {
}
}

@Controller(name = NotAutomaticallyCreated.NAME)
@ControllerConfiguration(name = NotAutomaticallyCreated.NAME)
static class NotAutomaticallyCreated implements Reconciler<TestCustomResource> {

public static final String NAME = "should-be-logged";
Expand All @@ -132,7 +133,7 @@ public UpdateControl<TestCustomResource> reconcile(
}
}

@Controller(generationAwareEventProcessing = false, name = "test")
@ControllerConfiguration(generationAwareEventProcessing = false, name = "test")
static class TestCustomReconciler implements Reconciler<TestCustomResource> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.slf4j.LoggerFactory;

import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.Controller;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider;

@Controller
@ControllerConfiguration
public class DoubleUpdateTestCustomReconciler
implements Reconciler<DoubleUpdateTestCustomResource>, TestExecutionInfoProvider {

Expand Down
Loading