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
Copy file name to clipboardExpand all lines: docs/content/en/docs/documentation/reconciler.md
+31-37Lines changed: 31 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,26 +170,20 @@ annotation. If you do not specify a finalizer name, one will be automatically ge
170
170
171
171
From v5, by default, the finalizer is added using Server Side Apply. See also `UpdateControl` in docs.
172
172
173
-
### Making sure primary is up to date for the next reconciliation
174
-
175
-
When you implement a reconciler as a final step (but maybe also multiple times during one reconciliation), you
176
-
usually update the status subresource with the information that was available during the reconciliation.
177
-
Sometimes this is referred to as the last observed state.
178
-
When the resource is updated, the framework does not cache the resource directly from the response of the update.
179
-
Instead, the underlying informer eventually receives an event with the updated resource and caches the resource.
180
-
Therefore, it can happen that on next reconciliation the primary resource is not up-to-date regarding your updated status subresource (note that other event sources
181
-
can trigger the reconciliation meanwhile). This is not usually a problem, since the status is not used as an input,
182
-
the reconciliation runs again, and the status us updated again. The caches are eventually consistent.
183
-
184
-
However, there are cases when you would like to store some state in the status, typically generated
185
-
IDs of external resources.
186
-
See related topic in Kubernetes docs: [Representing Allocated Values](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#representing-allocated-values).
187
-
In this case, it is reasonable to expect to have the state always available for the next reconciliation,
188
-
to avoid generating the resource again and other race conditions.
189
-
190
-
Therefore,
191
-
the framework provides facilities
192
-
to cover these use cases with [`PrimaryUpdateAndCacheUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java#L16).
173
+
### Making sure the primary resource is up to date for the next reconciliation
174
+
175
+
It is typical to want to update the status subresource with the information that is available during the reconciliation.
176
+
This is sometimes referred to as the last observed state. When the primary resource is updated, though, the framework
177
+
does not cache the resource directly, relying instead on the propagation of the update to the underlying informer's
178
+
cache. It can, therefore, happen that, if other events trigger other reconciliations before the informer cache gets
179
+
updated, your reconciler does not see the latest version of the primary resource. While this might not typically be a
180
+
problem in most cases, as caches eventually become consistent, depending on your reconciliation logic, you might still
181
+
require the latest status version possible, for example if the status subresource is used as a communication mechanism,
182
+
see [Representing Allocated Values](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#representing-allocated-values)
183
+
from the Kubernetes docs for more details.
184
+
185
+
The framework provides utilities to help with these use cases with
@@ -214,20 +208,19 @@ public UpdateControl<StatusPatchCacheCustomResource> reconcile(
214
208
```
215
209
216
210
In the background `PrimaryUpdateAndCacheUtils.ssaPatchAndCacheStatus` puts the result of the update into an internal
217
-
cache of the event source of primary resource, and will make sure that the next reconciliation will contain the most
218
-
recent version of the resource. Note that it is not necessarily the version of the resource you got as response from the update ,
219
-
it can be newer since other parties can do additional updates meanwhile, but if not explicitly modified,
220
-
it will contain the up-to-date status.
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.
221
214
222
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).
223
216
224
217
This approach works with the default configuration of the framework and should be good to go in most of the cases.
225
-
Without going further into the details, this won't work if `ConfigurtionService.parseResourceVersionsForEventFilteringAndCaching`
218
+
Without going further into the details, this won't work if `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
226
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:
227
220
228
221
#### Fallback approach: using `PrimaryResourceCache` cache
229
222
230
-
As an alternative, for very rare cases when `ConfigurtionService.parseResourceVersionsForEventFilteringAndCaching`
223
+
As an alternative, for very rare cases when `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
231
224
needs to be set to `false` you can use an explicit caching approach:
232
225
233
226
```java
@@ -244,7 +237,7 @@ needs to be set to `false` you can use an explicit caching approach:
As shown in the example above, it is up to you to provide a predicate to determine if the resource is more recent than the one available.
277
-
In other words, when to evict the resource from the cache. Typically, as show in the [integration test](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/primarycache)
278
-
you can have a counter in status to check on that.
268
+
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.
279
273
280
-
Since all of this happens explicitly, you cannot use this approach for managed dependent resources and workflows (you can still use not managed);
281
-
Since passing of the primary resource to the dependent resource always comes directly from the underlying informer event
282
-
source cache.
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.
283
277
284
278
#### Additional remarks
285
279
286
280
As shown in the integration tests, there is no optimistic locking used when updating the
0 commit comments