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
var updatedResource =PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResource(resource, freshCopy, context);
207
+
var updatedResource =PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResourceWithLock(resource, freshCopy, context);
205
208
206
209
returnUpdateControl.noUpdate();
207
210
}
208
211
```
209
212
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
+
After the update`PrimaryUpdateAndCacheUtils.ssaPatchStatusAndCacheResourceWithLock` puts the result of the update into an internal
214
+
cache and will the framework will make sure that the next reconciliation will contain the most recent version of the resource.
215
+
Note that it is not necessarily the version of the resource you got as response from the update, it can be newer since other parties
213
216
can do additional updates meanwhile, but if not explicitly modified, it will contain the up-to-date status.
214
217
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).
218
+
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/internalwithlock).
216
219
217
220
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:
221
+
222
+
Without going further into the details, a bit more experimental way we provide overloaded methods without optimistic locking,
223
+
to use those you have to set `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
224
+
to `true`. This in practice would mean that request won't fail on optimistic locking, but requires bending a bit
225
+
the rules regarding Kubernetes API contract. This might be needed only if you have multiple resources frequently
226
+
writing the resource.
220
227
221
228
#### Fallback approach: using `PrimaryResourceCache` cache
222
229
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:
230
+
For the sake of completeness, we also provide a more explicit approach to manage the cache yourself.
231
+
This approach has the advantage that you don't have to do neither optimistic locking nor
232
+
setting the `parseResourceVersionsForEventFilteringAndCaching` to `true`:
225
233
226
234
```java
227
235
@@ -277,9 +285,7 @@ their associated primary resource from the underlying informer event source cach
277
285
278
286
#### Additional remarks
279
287
280
-
As shown in the integration tests, there is no optimistic locking used when updating the
288
+
As shown in the last two cases, 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
-
285
-
In addition, you can configure the [Fabric8 client retry](https://github.com/fabric8io/kubernetes-client?tab=readme-ov-file#configuring-the-client).
290
+
(in other words `metadata.resourceVersion` is set to `null`). This has nice property the request will be successful.
291
+
However, it might be desirable to configure retry on [Fabric8 client](https://github.com/fabric8io/kubernetes-client?tab=readme-ov-file#configuring-the-client).
Copy file name to clipboardExpand all lines: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java
Copy file name to clipboardExpand all lines: operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,10 @@ public UpdateControl<StatusPatchCacheCustomResource> reconcile(
31
31
+ resource.getStatus().getValue());
32
32
}
33
33
34
+
// test also resource update happening meanwhile reconciliation
Copy file name to clipboardExpand all lines: operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internalwithlock/StatusPatchCacheWithLockReconciler.java
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,10 @@ public UpdateControl<StatusPatchCacheWithLockCustomResource> reconcile(
33
33
+ resource.getStatus().getValue());
34
34
}
35
35
36
+
// test also resource update happening meanwhile reconciliation
Copy file name to clipboardExpand all lines: operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheReconciler.java
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,10 @@ public UpdateControl<StatusPatchPrimaryCacheCustomResource> reconcile(
46
46
+ primary.getStatus().getValue());
47
47
}
48
48
49
+
// test also resource update happening meanwhile reconciliation
Copy file name to clipboardExpand all lines: operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache/StatusPatchPrimaryCacheSpec.java
0 commit comments