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
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,43 +211,50 @@ updated via `PrimaryUpdateAndCacheUtils`.
211
211
212
212
See related integration test [here](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache).
213
213
214
-
### Trigger reconciliation on all events
214
+
### Trigger reconciliation even for `Delete` events
215
215
216
216
TLDR; We provide an execution mode where `reconcile` method is called on every event from event source.
217
217
218
-
The framework optimizes execution for generic use cases, which in almost all cases falls into two categories:
218
+
The framework optimizes execution for generic use cases, which, in almost all cases, fall into two categories:
219
219
220
-
1. The controller does not use finalizers; thus when the primary resource is deleted, all the managed secondary
221
-
resources are cleaned up using the Kubernetes garbage collection mechanism, a.k.a., using owner references.
222
-
2. When finalizers are used (using `Cleaner` interface), thus when controller requires some explicit cleanup logic, typically for external
223
-
resources and when secondary resources are in different namespace than the primary resources (owner references
224
-
cannot be used in this case).
220
+
1. The controller does not use finalizers; thus when the primary resource is deleted, all the managed secondary
221
+
resources are cleaned up using the Kubernetes garbage collection mechanism, a.k.a., using owner references. This
222
+
mechanism, however, only works when all secondary resources are Kubernetes resources in the same namespace as the
223
+
primary resource.
224
+
2. The controller uses finalizers (the controller implements the `Cleaner` interface), when explicit cleanup logic is
225
+
required, typically for external resources and when secondary resources are in different namespace than the primary
226
+
resources (owner references cannot be used in this case).
225
227
226
-
Note that for example framework neither of those cases triggers the reconciler on the `Delete` event of the primary resource.
227
-
When finalizer is used, it calls `cleaner(..)` method when resource is marked for deletion and our (not other) finalizer
228
-
is present. When there is no finalizer, does not make sense to call the `reconciel(..)` method on a `Delete` event
229
-
since all the cleanup will be done by the garbage collector. This way we spare reconciliation cycles.
228
+
Note that neither of those cases trigger the `reconcile` method of the controller on the `Delete` event of the primary
229
+
resource. When a finalizer is used, the SDK calls the `cleanup` method of the `Cleaner` implementation when the resource
230
+
is marked for deletion and the finalizer specified by the controller is present on the primary resource. When there is
231
+
no finalizer, there is no need to call the `reconcile` method on a `Delete` event since all the cleanup will be done by
232
+
the garbage collector. This avoids reconciliation cycles.
230
233
231
234
However, there are cases when controllers do not strictly follow those patterns, typically when:
232
-
- Only some of the primary resources use finalizers, e.g., for some of the primary resources you need
235
+
236
+
- Only some of the primary resources use finalizers, e.g., for some of the primary resources you need
233
237
to create an external resource for others not.
234
238
- You maintain some additional in memory caches (so not all the caches are encapsulated by an `EventSource`)
235
239
and you don't want to use finalizers. For those cases, you typically want to clean up your caches when the primary
236
240
resource is deleted.
237
241
238
242
For such use cases you can set [`triggerReconcilerOnAllEvent`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ControllerConfiguration.java#L81)
239
-
to `true`, as a result, `reconcile` method will be triggered on ALL events (so also `Delete` events), and you
240
-
are free to optimize you reconciliation for the use cases above and possibly others.
243
+
to `true`, as a result, the `reconcile` method will be triggered on ALL events (so also `Delete` events), making it
244
+
possible to support the above use cases.
241
245
242
246
In this mode:
247
+
243
248
- even if the primary resource is already deleted from the Informer's cache, we will still pass the last known state
244
-
as the parameter for the reconciler. You can check if the resource is deleted using `Context.isPrimaryResourceDeleted()`.
245
-
- The retry, rate limiting, re-schedule, filters mechanisms work normally. (The internal caches related to the resource
246
-
are cleaned up only when there was a successful reconiliation after `Delete` event received for the primary resource
247
-
and reconciliation was not re-scheduled.
248
-
- you cannot use `Cleaner` interface. The framework assumes you will explicitly manage the finalizers. To
249
-
add finalizer you can use [`PrimeUpdateAndCacheUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java#L308).
249
+
as the parameter for the reconciler. You can check if the resource is deleted using
250
+
`Context.isPrimaryResourceDeleted()`.
251
+
- The retry, rate limiting, re-schedule, filters mechanisms work normally. The internal caches related to the resource
252
+
are cleaned up only when there is a successful reconciliation after a `Delete` event was received for the primary
253
+
resource
254
+
and reconciliation is not re-scheduled.
255
+
- you cannot use the `Cleaner` interface. The framework assumes you will explicitly manage the finalizers. To
0 commit comments