Skip to content

Commit 717933b

Browse files
committed
fix: wording & typos
Signed-off-by: Chris Laprun <claprun@redhat.com>
1 parent f12955b commit 717933b

File tree

1 file changed

+31
-37
lines changed

1 file changed

+31
-37
lines changed

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

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,20 @@ annotation. If you do not specify a finalizer name, one will be automatically ge
170170

171171
From v5, by default, the finalizer is added using Server Side Apply. See also `UpdateControl` in docs.
172172

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
186+
[`PrimaryUpdateAndCacheUtils`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/PrimaryUpdateAndCacheUtils.java).
193187
These utility methods come in two flavors:
194188

195189
#### Using internal cache
@@ -214,20 +208,19 @@ public UpdateControl<StatusPatchCacheCustomResource> reconcile(
214208
```
215209

216210
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.
221214

222215
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).
223216

224217
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`
226219
is set to `false` (more precisely there are some edge cases when it won't work). For that case framework provides the following solution:
227220

228221
#### Fallback approach: using `PrimaryResourceCache` cache
229222

230-
As an alternative, for very rare cases when `ConfigurtionService.parseResourceVersionsForEventFilteringAndCaching`
223+
As an alternative, for very rare cases when `ConfigurationService.parseResourceVersionsForEventFilteringAndCaching`
231224
needs to be set to `false` you can use an explicit caching approach:
232225

233226
```java
@@ -244,7 +237,7 @@ needs to be set to `false` you can use an explicit caching approach:
244237
StatusPatchPrimaryCacheCustomResource primary,
245238
Context<StatusPatchPrimaryCacheCustomResource> context) {
246239

247-
// cache will compare the current and the cached resource and return the more recent. (And evic the old)
240+
// cache will compare the current and the cached resource and return the more recent. (And evict the old)
248241
primary = cache.getFreshResource(primary);
249242

250243
// omitted logic
@@ -272,20 +265,21 @@ needs to be set to `false` you can use an explicit caching approach:
272265
```
273266

274267
[`PrimaryResourceCache`](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/support/PrimaryResourceCache.java)
275-
is designed for this purpose.
276-
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.
279273

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.
283277

284278
#### Additional remarks
285279

286280
As shown in the integration tests, there is no optimistic locking used when updating the
287281
[resource](https://github.com/operator-framework/java-operator-sdk/blob/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/statuscache/internal/StatusPatchCacheReconciler.java#L41)
288-
(in other works `metadata.resourceVersion` is set to `null`).
289-
This is desired since you don't want the patch to fail on update.
282+
(in other words `metadata.resourceVersion` is set to `null`). This is desired since you don't want the patch to fail on
283+
update.
290284

291-
In addition, you can configure retry for in fabric8 client.
285+
In addition, you can configure the Fabric8 client retry.

0 commit comments

Comments
 (0)