Skip to content

Commit 0d49575

Browse files
committed
docs
Signed-off-by: Attila Mészáros <[email protected]>
1 parent bc2cf5b commit 0d49575

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

docs/content/en/docs/documentation/reconciler.md

+37-6
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,39 @@ These utility methods come in two flavors:
188188

189189
#### Using internal cache
190190

191-
In almost all cases for this purpose, you can use internal caches:
191+
In almost all cases for this purpose, you can use internal caches. You can turn on this functionality for
192+
`UpdateControl`, thus all updates for `UpdateControl` will be guaranteed to be present in the next reconciliation:
192193

193194
```java
194-
@Override
195+
Operator operator = new Operator(o -> o
196+
.withParseResourceVersions(true)
197+
.withGuaranteeUpdatedPrimaryIsAvailableForNextReconciliation(true));
198+
```
199+
200+
With this setup the following trivial code will cache the resource for the next reconciliation:
201+
202+
```java
203+
204+
@Override
205+
public UpdateControl<UpdateControlPrimaryCacheCustomResource> reconcile(
206+
UpdateControlPrimaryCacheCustomResource resource,
207+
Context<UpdateControlPrimaryCacheCustomResource> context) {
208+
209+
// your logic omitted
210+
var freshCopy = createFreshCopy(resource); // create fresh copy for SSA
211+
freshCopy.getStatus().setValue(statusWithState());
212+
213+
return UpdateControl.patchStatus(freshCopy);
214+
}
215+
```
216+
See related [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/updatecontrol/UpdateControlPrimaryCacheCustomResource.java).
217+
218+
If you need to do update of the resource during the reconciliation you can just use `PrimaryUpdateAndCacheUtils`.
219+
(The code below is equivalent to the one above.)
220+
Note that this utility does not require to set `withGuaranteeUpdatedPrimaryIsAvailableForNextReconciliation` to true.
221+
222+
```java
223+
@Override
195224
public UpdateControl<StatusPatchCacheCustomResource> reconcile(
196225
StatusPatchCacheCustomResource resource, Context<StatusPatchCacheCustomResource> context) {
197226

@@ -207,10 +236,12 @@ public UpdateControl<StatusPatchCacheCustomResource> reconcile(
207236
}
208237
```
209238

210-
In the background `PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus` puts the result of the update into an internal
211-
cache and will make sure that the next reconciliation will contain the most recent version of the resource. Note that it
212-
is not necessarily the version of the resource you got as response from the update, it can be newer since other parties
213-
can do additional updates meanwhile, but if not explicitly modified, it will contain the up-to-date status.
239+
In the background `PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus` and also the mechanism behind `UpdateControl.patchStatus`
240+
puts the result of the update into an internal cache and will make sure that the next reconciliation will contain the
241+
most recent version of the resource.
242+
Note that it is not necessarily the version of the resource you got as a response
243+
from the update, it can be more recent since other parties can do additional updates meanwhile.
244+
But if not explicitly modified by another party, it will contain the up-to-date status.
214245

215246
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/internal).
216247

0 commit comments

Comments
 (0)