Skip to content

fix: use appropriate terms where needed #790

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 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions docs/documentation/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ Always update the custom resource with `UpdateControl`, not with the actual kube
On resource updates there is always an optimistic version control in place, to make sure that another update is not
overwritten (by setting `resourceVersion` ) .

The `DeleteControl` typically instructs the framework to remove the finalizer after the dependent resource are cleaned
up in `cleanup` implementation.

However, there is a possibility to not remove the finalizer, this allows to clean up the resources in a more async way,
mostly for the cases when there is a long waiting period after a delete operation is initiated. Note that in this case
you might want to either schedule a timed event to make sure the
`deleteResource` is executed again or use event sources get notified about the state changes of a deleted resource.
The `DeleteControl` typically instructs the framework to remove the finalizer after the dependent
resource are cleaned up in `cleanup` implementation.

However, there is a possibility to not remove the finalizer, this allows to clean up the resources
in a more async way, mostly for the cases when there is a long waiting period after a delete
operation is initiated. Note that in this case you might want to either schedule a timed event to
make sure
`cleanup` is executed again or use event sources get notified about the state changes of a deleted
resource.

## Generation Awareness and Automatic Observed Generation Handling

Expand Down
47 changes: 26 additions & 21 deletions docs/documentation/v2-migration.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
---
title: Migrating from v1 to v2
description: Migrating from v1 to v2
layout: docs
permalink: /docs/v2-migration
title: Migrating from v1 to v2 description: Migrating from v1 to v2 layout: docs permalink:
/docs/v2-migration
---

# Migrating from v1 to v2

Version 2 of the framework introduces improvements, features and breaking changes for the APIs both internal and user
facing ones. The migration should be however trivial in most of the cases. For detailed overview of all major issues
until the release of
v`2.0.0` [see milestone on GitHub](https://github.com/java-operator-sdk/java-operator-sdk/milestone/1). For a summary
and reasoning behind some naming changes
Version 2 of the framework introduces improvements, features and breaking changes for the APIs both
internal and user facing ones. The migration should be however trivial in most of the cases. For
detailed overview of all major issues until the release of
v`2.0.0` [see milestone on GitHub](https://github.com/java-operator-sdk/java-operator-sdk/milestone/1)
. For a summary and reasoning behind some naming changes
see [this issue](https://github.com/java-operator-sdk/java-operator-sdk/issues/655)

## User Facing API Changes
Expand All @@ -26,28 +24,35 @@ The following items are renamed and slightly changed:
- `deleteResource` renamed to `cleanup`
- Events are removed from
the [`Context`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java)
of `Reconciler` methods . The rationale behind this, is that there is a consensus now on the pattern that the events
should not be used to implement a reconciliation logic.
of `Reconciler` methods . The rationale behind this, is that there is a consensus now on the
pattern that the events should not be used to implement a reconciliation logic.
- The `init` method is extracted from `ResourceController` / `Reconciler` to a separate interface
called [EventSourceInitializer](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/EventSourceInitializer.java)
that `Reconcile` should implement in order to register event sources. See
that `Reconciler` should implement in order to register event sources. The method has been renamed
to `prepareEventSources` and should now return a list of `EventSource` implementations that
the `Controller` will automatically register. See
also [sample](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/tomcat-operator/src/main/java/io/javaoperatorsdk/operator/sample/WebappReconciler.java)
for usage. Here also
the [`EventSourceManager`](https://github.com/java-operator-sdk/java-operator-sdk/blob/v1/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java)
is renamed
to [`EventSourceRegistry`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSourceRegistry.java)
, and it's interface refined.
for usage.
- [`EventSourceManager`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java)
is now an internal class that users shouldn't need to interact with.
- [`@Controller`](https://github.com/java-operator-sdk/java-operator-sdk/blob/v1/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java)
annotation renamed
to [`@ControllerConfiguration`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java)
- The metrics use `reconcile`, `cleanup` and `resource` labels instead of `createOrUpdate`, `delete`
and `cr`, respectively to match the new logic.

### Event Sources

- Addressing resources within event sources (and in the framework internally) is now changed from `.metadata.uid` to a
pair of `.metadata.name` and optional `.metadata.namespace` of resource. Represented
- Addressing resources within event sources (and in the framework internally) is now changed
from `.metadata.uid` to a pair of `.metadata.name` and optional `.metadata.namespace` of resource.
Represented
by [`ResourceID.`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ResourceID.java)
- The [`Event`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/Event.java)
API is simplified. Now if an event source produces an event it needs to just produce an instance of this class.
-

The [`Event`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/Event.java)
API is simplified. Now if an event source produces an event it needs to just produce an instance of
this class.

- [`EventSource`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/EventSource.java)
is refactored, but the changes are trivial.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public boolean isRemoveFinalizer() {
@Override
public DeleteControl rescheduleAfter(long delay) {
if (removeFinalizer) {
throw new IllegalStateException("Cannot reschedule deleteResource if removing finalizer");
throw new IllegalStateException("Cannot reschedule cleanup if removing finalizer");
}
return super.rescheduleAfter(delay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public DeleteControl cleanup(R resource, Context context) {
new ControllerExecution<>() {
@Override
public String name() {
return "delete";
return "cleanup";
}

@Override
Expand All @@ -70,7 +70,7 @@ public UpdateControl<R> reconcile(R resource, Context context) {
new ControllerExecution<>() {
@Override
public String name() {
return "createOrUpdate";
return "reconcile";
}

@Override
Expand All @@ -80,7 +80,7 @@ public String controllerName() {

@Override
public String successTypeName(UpdateControl<R> result) {
String successType = "cr";
String successType = "resource";
if (result.isUpdateStatus()) {
successType = "status";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
import io.fabric8.kubernetes.client.dsl.Resource;
import io.javaoperatorsdk.operator.api.ObservedGenerationAware;
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.*;
import io.javaoperatorsdk.operator.api.reconciler.BaseControl;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.DefaultContext;
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl;
import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.processing.Controller;

import static io.javaoperatorsdk.operator.processing.KubernetesResourceUtils.getName;
Expand Down Expand Up @@ -80,8 +87,8 @@ private PostExecutionControl<R> handleDispatch(ExecutionScope<R> executionScope)
* {@link Reconciler#cleanup(HasMetadata, Context)} method
*
* @param resource the resource to be potentially deleted
* @return {@code true} if the resource should be handed to the controller's {@code
* deleteResource} method, {@code false} otherwise
* @return {@code true} if the resource should be handed to the controller's
* {@link Reconciler#cleanup(HasMetadata, Context)} method, {@code false} otherwise
*/
private boolean shouldNotDispatchToDelete(R resource) {
// we don't dispatch to delete if the controller is configured to use a finalizer but that
Expand Down Expand Up @@ -133,7 +140,7 @@ private R cloneResourceForErrorStatusHandlerIfNeeded(R resource, Context context
private PostExecutionControl<R> reconcileExecution(ExecutionScope<R> executionScope,
R resourceForExecution, R originalResource, Context context) {
log.debug(
"Executing createOrUpdate for resource {} with version: {} with execution scope: {}",
"Reconciling resource {} with version: {} with execution scope: {}",
getName(resourceForExecution),
getVersion(resourceForExecution),
executionScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public UpdateControl<MySQLSchema> reconcile(MySQLSchema schema, Context context)

@Override
public DeleteControl cleanup(MySQLSchema schema, Context context) {
log.info("Execution deleteResource for: {}", schema.getMetadata().getName());
log.info("Cleaning up for: {}", schema.getMetadata().getName());
try (Connection connection = getConnection()) {
var dbSchema = SchemaService.getSchema(connection, schema.getMetadata().getName());
if (dbSchema.isPresent()) {
Expand Down
23 changes: 12 additions & 11 deletions sample-operators/tomcat-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ run `kubectl apply -f k8s/operator.yaml`. Now you can create Tomcat instances wi
above).

## EventSources
The TomcatController is listening to events about Deployments created by the TomcatOperator by registering a
InformerEventSource with the EventSourceManager. The InformerEventSource will in turn register a watch on
all Deployments managed by the Controller (identified by the `app.kubernetes.io/managed-by` label).
When an event from a Deployment is received we have to identify which Tomcat object does the Deployment
belong to. This is done when the InformerEventSource creates the event.

The TomcatController has to take care of setting the `app.kubernetes.io/managed-by` label on the Deployment so the
InformerEventSource can watch the right Deployments.
The TomcatController also has to set `ownerReference` on the Deployment so later the InformerEventSource can
identify which Tomcat does the Deployment belong to. This is necessary so the frameowork can call the Controller
`createOrUpdate` method correctly.
The TomcatController is listening to events about Deployments created by the TomcatOperator by
registering a InformerEventSource with the EventSourceManager. The InformerEventSource will in turn
register a watch on all Deployments managed by the Controller (identified by
the `app.kubernetes.io/managed-by` label). When an event from a Deployment is received we have to
identify which Tomcat object does the Deployment belong to. This is done when the
InformerEventSource creates the event.

The TomcatController has to take care of setting the `app.kubernetes.io/managed-by` label on the
Deployment so the InformerEventSource can watch the right Deployments. The TomcatController also has
to set `ownerReference` on the Deployment so later the InformerEventSource can identify which Tomcat
does the Deployment belong to. This is necessary so the framework can call the Controller
`reconcile` method correctly.

Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context context) {

@Override
public DeleteControl cleanup(WebPage nginx, Context context) {
log.info("Execution deleteResource for: {}", nginx.getMetadata().getName());
log.info("Cleaning up for: {}", nginx.getMetadata().getName());

log.info("Deleting ConfigMap {}", configMapName(nginx));
Resource<ConfigMap> configMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@ControllerConfiguration
public class CustomServiceReconciler implements Reconciler<CustomService> {

public static final String KIND = "CustomService";
private static final Logger log = LoggerFactory.getLogger(CustomServiceReconciler.class);

private final KubernetesClient kubernetesClient;
Expand All @@ -32,14 +31,14 @@ public CustomServiceReconciler(KubernetesClient kubernetesClient) {

@Override
public DeleteControl cleanup(CustomService resource, Context context) {
log.info("Execution deleteResource for: {}", resource.getMetadata().getName());
return DeleteControl.defaultDelete();
log.info("Cleaning up for: {}", resource.getMetadata().getName());
return Reconciler.super.cleanup(resource, context);
}

@Override
public UpdateControl<CustomService> reconcile(
CustomService resource, Context context) {
log.info("Execution createOrUpdateResource for: {}", resource.getMetadata().getName());
log.info("Reconciling: {}", resource.getMetadata().getName());

ServicePort servicePort = new ServicePort();
servicePort.setPort(8080);
Expand Down