Skip to content

Commit 76088c1

Browse files
csvirimetacosm
andauthored
docs: reconciler improvements (#2740)
Co-authored-by: Chris Laprun <[email protected]>
1 parent d1c3078 commit 76088c1

File tree

1 file changed

+40
-47
lines changed

1 file changed

+40
-47
lines changed

docs/content/en/docs/documentation/reconciler.md

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,47 @@ weight: 45
55

66
## Reconciliation Execution in a Nutshell
77

8-
Reconciliation execution is always triggered by an event. Events typically come from a
9-
primary resource, most of the time a custom resource, triggered by changes made to that resource
10-
on the server (e.g. a resource is created, updated or deleted). Reconciler implementations are
11-
associated with a given resource type and listens for such events from the Kubernetes API server
8+
An event always triggers reconciliation execution. Events typically come from a
9+
primary resource, usually a custom resource, triggered by changes made to that resource
10+
on the server (e.g. a resource is created, updated, or deleted) or from secondary resources for which there is a registered event source.
11+
Reconciler implementations are associated with a given resource type and listen for such events from the Kubernetes API server
1212
so that they can appropriately react to them. It is, however, possible for secondary sources to
13-
trigger the reconciliation process. This usually occurs via
13+
trigger the reconciliation process. This occurs via
1414
the [event source](#handling-related-events-with-event-sources) mechanism.
1515

16-
When an event is received reconciliation is executed, unless a reconciliation is already
17-
underway for this particular resource. In other words, the framework guarantees that no
18-
concurrent reconciliation happens for any given resource.
16+
When we receive an event, it triggers the reconciliation unless a reconciliation is already
17+
underway for this particular resource. In other words, the framework guarantees that no concurrent reconciliation happens for a resource.
1918

2019
Once the reconciliation is done, the framework checks if:
2120

22-
- an exception was thrown during execution and if yes schedules a retry.
23-
- new events were received during the controller execution, if yes schedule a new reconciliation.
24-
- the reconcilier instructed the SDK to re-schedule a reconciliation at a later date, if yes
25-
schedules a timer event with the specified delay.
26-
- none of the above, the reconciliation is finished.
21+
- an exception was thrown during execution, and if yes, schedules a retry.
22+
- new events were received during the controller execution; if yes, schedule a new reconciliation.
23+
- the reconciler results explicitly re-scheduled (`UpdateControl.rescheduleAfter(..)`) a reconciliation with a time delay, if yes,
24+
schedules a timer event with the specific delay.
25+
- if none of the above applies, the reconciliation is finished.
2726

28-
In summary, the core of the SDK is implemented as an eventing system, where events trigger
27+
In summary, the core of the SDK is implemented as an eventing system where events trigger
2928
reconciliation requests.
3029

31-
## Implementing a [`Reconciler`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java) and/or [`Cleaner`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java)
30+
## Implementing a Reconciler and Cleaner interfaces
3231

33-
The lifecycle of a Kubernetes resource can be clearly separated into two phases from the
34-
perspective of an operator depending on whether a resource is created or updated, or on the
35-
other hand if it is marked for deletion.
32+
To implement a reconciler, you always have to implement the [`Reconciler`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Reconciler.java) interface.
3633

37-
This separation-related logic is automatically handled by the framework. The framework will always
38-
call the `reconcile` method, unless the custom resource is
39-
[marked from deletion](https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/#how-finalizers-work)
40-
. On the other, if the resource is marked from deletion and if the `Reconciler` implements the
41-
`Cleaner` interface, only the `cleanup` method will be called. Implementing the `Cleaner`
42-
interface allows developers to let the SDK know that they are interested in cleaning related
43-
state (e.g. out-of-cluster resources). The SDK will therefore automatically add a finalizer
44-
associated with your `Reconciler` so that the Kubernetes server doesn't delete your resources
45-
before your `Reconciler` gets a chance to clean things up.
46-
See [Finalizer support](#finalizer-support) for more details.
34+
The lifecycle of a Kubernetes resource can be separated into two phases depending on whether the resource has already been marked for deletion or not.
35+
36+
The framework out of the box supports this logic, it will always
37+
call the `reconcile` method unless the custom resource is
38+
[marked from deletion](https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/#how-finalizers-work).
39+
40+
On the other hand, if the resource is marked from deletion and if the `Reconciler` implements the
41+
[`Cleaner`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java) interface, only the `cleanup` method is called. By implementing this interface
42+
the framework will automatically handle (add/remove) the finalizers for you.
43+
44+
In short, if you need to provide explicit cleanup logic, you always want to use finalizers; for a more detailed explanation, see [Finalizer support](#finalizer-support) for more details.
4745

4846
### Using `UpdateControl` and `DeleteControl`
4947

50-
These two classes are used to control the outcome or the desired behaviour after the reconciliation.
48+
These two classes control the outcome or the desired behavior after the reconciliation.
5149

5250
The [`UpdateControl`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/UpdateControl.java)
5351
can instruct the framework to update the status sub-resource of the resource
@@ -75,13 +73,10 @@ without an update:
7573
}
7674
```
7775

78-
Note, though, that using `EventSources` should be preferred to rescheduling since the
79-
reconciliation will then be triggered only when needed instead than on a timely basis.
80-
81-
Those are the typical use cases of resource updates, however in some cases there it can happen that
82-
the controller wants to update the resource itself (for example to add annotations) or not perform
83-
any updates, which is also supported.
76+
Note, though, that using `EventSources` is the preferred way of scheduling since the
77+
reconciliation is triggered only when a resource is changed, not on a timely basis.
8478

79+
At the end of the reconciliation, you typically update the status sub-resources.
8580
It is also possible to update both the status and the resource with the `patchResourceAndStatus` method. In this case,
8681
the resource is updated first followed by the status, using two separate requests to the Kubernetes API.
8782

@@ -141,32 +136,30 @@ Kubernetes cluster (e.g. external resources), you might not need to use finalize
141136
use the
142137
Kubernetes [garbage collection](https://kubernetes.io/docs/concepts/architecture/garbage-collection/#owners-dependents)
143138
mechanism as much as possible by setting owner references for your secondary resources so that
144-
the cluster can automatically deleted them for you whenever the associated primary resource is
139+
the cluster can automatically delete them for you whenever the associated primary resource is
145140
deleted. Note that setting owner references is the responsibility of the `Reconciler`
146141
implementation, though [dependent resources](https://javaoperatorsdk.io/docs/dependent-resources)
147142
make that process easier.
148143

149-
If you do need to clean such state, you need to use finalizers so that their
144+
If you do need to clean such a state, you need to use finalizers so that their
150145
presence will prevent the Kubernetes server from deleting the resource before your operator is
151-
ready to allow it. This allows for clean up to still occur even if your operator was down when
152-
the resources was "deleted" by a user.
146+
ready to allow it. This allows for clean-up even if your operator was down when the resource was marked for deletion.
153147

154148
JOSDK makes cleaning resources in this fashion easier by taking care of managing finalizers
155149
automatically for you when needed. The only thing you need to do is let the SDK know that your
156-
operator is interested in cleaning state associated with your primary resources by having it
150+
operator is interested in cleaning the state associated with your primary resources by having it
157151
implement
158152
the [`Cleaner<P>`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Cleaner.java)
159153
interface. If your `Reconciler` doesn't implement the `Cleaner` interface, the SDK will consider
160-
that you don't need to perform any clean-up when resources are deleted and will therefore not
161-
activate finalizer support. In other words, finalizer support is added only if your `Reconciler`
162-
implements the `Cleaner` interface.
154+
that you don't need to perform any clean-up when resources are deleted and will, therefore, not activate finalizer support.
155+
In other words, finalizer support is added only if your `Reconciler` implements the `Cleaner` interface.
163156

164-
Finalizers are automatically added by the framework as the first step, thus after a resource
165-
is created, but before the first reconciliation. The finalizer is added via a separate
157+
The framework automatically adds finalizers as the first step, thus after a resource
158+
is created but before the first reconciliation. The finalizer is added via a separate
166159
Kubernetes API call. As a result of this update, the finalizer will then be present on the
167160
resource. The reconciliation can then proceed as normal.
168161

169-
The finalizer that is automatically added will be also removed after the `cleanup` is executed on
162+
The automatically added finalizer will also be removed after the `cleanup` is executed on
170163
the reconciler. This behavior is customizable as explained
171164
[above](#using-updatecontrol-and-deletecontrol) when we addressed the use of
172165
`DeleteControl`.
@@ -175,4 +168,4 @@ You can specify the name of the finalizer to use for your `Reconciler` using the
175168
[`@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)
176169
annotation. If you do not specify a finalizer name, one will be automatically generated for you.
177170

178-
From v5 by default finalizer is added using Served Side Apply. See also UpdateControl in docs.
171+
From v5, by default, the finalizer is added using Server Side Apply. See also `UpdateControl` in docs.

0 commit comments

Comments
 (0)