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
[`PrimaryUpdateAndCacheUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java) utility class
187
+
to help with these use cases.
188
188
189
-
#### Using internal cache
190
-
191
-
In almost all cases for this purpose, you can use internal caches:
189
+
This class' methods use internal caches in combination with update methods that leveraging
190
+
optimistic locking. If the update method fails on optimistic locking, it will retry
191
+
using a fresh resource from the server as base for modification.
var updatedResource =PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus(resource, freshCopy, context);
205
-
206
-
returnUpdateControl.noUpdate();
207
-
}
208
-
```
209
-
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.
214
-
215
-
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).
216
-
217
-
This approach works with the default configuration of the framework and should be good to go in most of the cases.
218
-
Without going further into the details, this won't work if `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
219
-
is set to `false` (more precisely there are some edge cases when it won't work). For that case framework provides the following solution:
220
-
221
-
#### Fallback approach: using `PrimaryResourceCache` cache
222
-
223
-
As an alternative, for very rare cases when `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
224
-
needs to be set to `false` you can use an explicit caching approach:
225
-
226
-
```java
227
-
228
-
// We on purpose don't use the provided predicate to show what a custom one could look like.
is designed for this purpose. As shown in the example above, it is up to you to provide a predicate to determine if the
269
-
resource is more recent than the one available. In other words, when to evict the resource from the cache. Typically, as
270
-
shown in
271
-
the [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache)
272
-
you can have a counter in status to check on that.
273
-
274
-
Since all of this happens explicitly, you cannot use this approach for managed dependent resources and workflows and
275
-
will need to use the unmanaged approach instead. This is due to the fact that managed dependent resources always get
276
-
their associated primary resource from the underlying informer event source cache.
277
-
278
-
#### Additional remarks
210
+
After the update `PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource` puts the result of the update into an internal
211
+
cache and the framework will make sure that the next reconciliation contains the most recent version of the resource.
212
+
Note that it is not necessarily the same version returned as response from the update, it can be a newer version since other parties
213
+
can do additional updates meanwhile. However, unless it has been explicitly modified, that
214
+
resource will contain the up-to-date status.
279
215
280
-
As shown in the integration tests, there is no optimistic locking used when updating the
(in other words `metadata.resourceVersion` is set to `null`). This is desired since you don't want the patch to fail on
283
-
update.
284
216
285
-
In addition, you can configure the [Fabric8 client retry](https://github.com/fabric8io/kubernetes-client?tab=readme-ov-file#configuring-the-client).
217
+
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).
0 commit comments