-
Notifications
You must be signed in to change notification settings - Fork 220
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
Changes from 14 commits
d478e35
3b76d5e
5919eac
74920ab
3f92747
fb58685
55b859d
6f07321
444f7d1
8b1be24
424f800
adc543a
1d148ac
9ec3471
910293a
349fc11
2e0ec8b
75b8e0e
8811dc3
224bcdf
94980ee
cadbc8a
0f9eaba
725fb06
b51e69b
0521f8e
4105def
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ dependencies { | |
``` | ||
|
||
Once you've added the dependency, define a main method initializing the Operator and registering a | ||
controller. | ||
controllerConfiguration. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
|
||
```java | ||
public class Runner { | ||
|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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? | ||
|
@@ -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 | | ||
| :--- | :--- | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -49,7 +49,7 @@ public ConfigurationService getConfigurationService() { | |
return configurationService; | ||
} | ||
|
||
public List<ConfiguredController> getControllers() { | ||
public List<Controller> getControllers() { | ||
return new ArrayList<>(controllers.controllers.values()); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
* @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() | ||
|
@@ -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() { | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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(); | ||
} | ||
} | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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