You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/en/docs/documentation/reconciler.md
+40-47Lines changed: 40 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -5,49 +5,47 @@ weight: 45
5
5
6
6
## Reconciliation Execution in a Nutshell
7
7
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
12
12
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
14
14
the [event source](#handling-related-events-with-event-sources) mechanism.
15
15
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.
19
18
20
19
Once the reconciliation is done, the framework checks if:
21
20
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.
27
26
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
29
28
reconciliation requests.
30
29
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 andCleaner interfaces
32
31
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.
36
33
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.
47
45
48
46
### Using `UpdateControl` and `DeleteControl`
49
47
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.
51
49
52
50
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)
53
51
can instruct the framework to update the status sub-resource of the resource
@@ -75,13 +73,10 @@ without an update:
75
73
}
76
74
```
77
75
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.
84
78
79
+
At the end of the reconciliation, you typically update the status sub-resources.
85
80
It is also possible to update both the status and the resource with the `patchResourceAndStatus` method. In this case,
86
81
the resource is updated first followed by the status, using two separate requests to the Kubernetes API.
87
82
@@ -141,32 +136,30 @@ Kubernetes cluster (e.g. external resources), you might not need to use finalize
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
145
140
deleted. Note that setting owner references is the responsibility of the `Reconciler`
146
141
implementation, though [dependent resources](https://javaoperatorsdk.io/docs/dependent-resources)
147
142
make that process easier.
148
143
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
150
145
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.
153
147
154
148
JOSDK makes cleaning resources in this fashion easier by taking care of managing finalizers
155
149
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
157
151
implement
158
152
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)
159
153
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.
163
156
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
166
159
Kubernetes API call. As a result of this update, the finalizer will then be present on the
167
160
resource. The reconciliation can then proceed as normal.
168
161
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
170
163
the reconciler. This behavior is customizable as explained
171
164
[above](#using-updatecontrol-and-deletecontrol) when we addressed the use of
172
165
`DeleteControl`.
@@ -175,4 +168,4 @@ You can specify the name of the finalizer to use for your `Reconciler` using the
0 commit comments