Skip to content

Commit 52b7465

Browse files
committed
docs: best practices
1 parent b03df5d commit 52b7465

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

docs/documentation/patterns-best-practices.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@ permalink: /docs/patterns-best-practices
77

88
# Patterns and Best Practices
99

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.
1212

1313
## Implementing a Reconciler
1414

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`.
1628

1729
### Idempotency
1830

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.
2035

2136
### Sync of Async Way of Resource Handling
2237

0 commit comments

Comments
 (0)