@@ -7,16 +7,31 @@ permalink: /docs/patterns-best-practices
7
7
8
8
# Patterns and Best Practices
9
9
10
- This document describes patters and best practices, to build and run operators, and how to implement them in terms
11
- of Java Operator SDK.
10
+ This document describes patters and best practices, to build and run operators, and how to implement them in terms of
11
+ Java Operator SDK.
12
12
13
13
## Implementing a Reconciler
14
14
15
- ### Reconcile All The Resource All the Time
15
+ ### Reconcile All The Resources All the Time
16
+
17
+ The reconciliation can be triggered by events from multiple sources. It could be tempting to check the events, and
18
+ reconcile just the related resource or subset of resources that controller manages. However, this is ** considered as an
19
+ anti-pattern** in operators. If triggered, all resources should be reconciled. Note that usually this means only
20
+ comparing the target state with the current state in the cache. The reason behind this is events not reliable in
21
+ general, thus means events can be lost.
22
+
23
+ In addition to that such approach might even complicate implementation logic in the ` Reconciler ` , since parallel
24
+ execution of the reconciler is not allowed for the same custom resource, there can be multiple events received for the
25
+ same resource or dependent resource during an ongoing execution, ordering those events could be also challenging.
26
+
27
+ For this reason from v2 the events are not even accessible for the ` Reconciler ` .
16
28
17
29
### Idempotency
18
30
19
- ### Managing Resources
31
+ Since all the resources are reconciled during an execution and an execution can be triggered quite often, also
32
+ retries of a reconciliation can happen naturally in operators, the implementation of a ` Reconciler `
33
+ needs to be idempotent. Luckily, since operators are usually managing already declarative resources, this is trivial
34
+ to do in most cases.
20
35
21
36
### Sync of Async Way of Resource Handling
22
37
0 commit comments