Skip to content

Commit f785fa3

Browse files
committed
improve
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 0af3216 commit f785fa3

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

docs/content/en/blog/news/primary-cache-for-next-recon.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ author: >-
77

88
We recently released v5.1 of Java Operator SDK. One of the highlights of this release is related to a topic of so-called
99
[allocated values](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#representing-allocated-values
10-
) in Kubernetes.
10+
).
1111

12-
To sum up the problem, let's say if we create a resource from our controller that has a generated ID -
13-
in other words, we cannot address the resource only by using the values from the `.spec` -
14-
we have to store this ID, usually in the `.status` of the custom resource. However, operator frameworks cache resources
12+
To describe the problem, let's say if we create a resource from our controller that has a generated ID
13+
we have to store this ID, usually in the `.status` of the custom resource.
14+
(In other words, we cannot address the resource only by using the values from the `.spec`.)
15+
However, operator frameworks cache resources
1516
using informers, so the update that you made to the status of the custom resource will just eventually get into
1617
the cache of the informer. If meanwhile some other event triggers the reconciliation, it can happen that we will
1718
see the stale custom resource in the cache (in another word, the cache is eventually consistent) without the generated ID in the status.
@@ -47,7 +48,7 @@ but ultimately, we only provided the solution below. (If you want to dig deep in
4748

4849
The trick is to cache the resource from the response of our update in an additional cache on top of the informer's cache.
4950
If we read the resource, we first check if it is in the overlay cache and read it from there if present, otherwise read it from the cache of the informer.
50-
If the informer receives an event with that resource, we always remove the resource from the overlay
51+
If the informer receives an event with a fresh resource, we always remove the resource from the overlay
5152
cache, since that is a more recent resource. But this **works only** if the update is done **with optimistic locking**.
5253
So if the update fails on conflict, we simply wait and poll the informer cache until there is a new resource version,
5354
and try to update again using the new resource (applied our changes again) with optimistic locking.
@@ -57,7 +58,7 @@ another party does an update on the resource just before we do. The informer rec
5758
if we would compare resource versions with this resource and the previously cached resource (response from our update),
5859
that would be different, and in general there is no elegant way to determine if this new version that
5960
informer receives an event from an update that happened before or after our update.
60-
(Note that informers watch can lose connection and other edge cases)
61+
(Note that informer's watch can lose connection and other edge cases)
6162

6263

6364
```mermaid
@@ -72,12 +73,11 @@ flowchart TD
7273
7374
```
7475

75-
76-
If we do our update with optimistic locking, it simplifies the situation, we can easily have strong guarantees.
77-
Since we know if the update with optimistic locking is successful, we have the fresh resource in our cache.
76+
If we do our update with optimistic locking, it simplifies the situation, and we can have strong guarantees.
77+
Since we know if the update with optimistic locking is successful, we have the up-to-date resource in our caches.
7878
Thus, the next event we receive will be the one that is the result of our update
7979
(or a newer one if somebody did an update after, but that is fine since it will contain our allocated values).
8080
So if we cache the resource in the overlay cache from the response, we know that with the next event, we can remove it from there.
81-
Note that we store the result in overlay cache only if at that time we still have the original resource in cache,
82-
if the cache already updated. This means that we already received a new event after our update,
83-
so we have a fresh resource in the informer cache.
81+
Note that we store the result in overlay cache only if at that time we still have the original resource in cache.
82+
If the cache already updated, that means that we already received a new event after our update,
83+
so we have a fresh resource in the informer cache already.

0 commit comments

Comments
 (0)