Skip to content

Commit 08e1b34

Browse files
committed
improvements
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 935637c commit 08e1b34

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,28 @@ default boolean parseResourceVersionsForEventFilteringAndCaching() {
465465
}
466466

467467
/**
468-
* If you update the primary resource from the reconciler with or without {@link
469-
* io.javaoperatorsdk.operator.api.reconciler.UpdateControl} it is not guaranteed that for the
470-
* next reconciliation will receive the most up-to-date resource. This is a consequence of
471-
* Informers design in the Operator pattern.
468+
* Guarantees that primary resource updated by {@link
469+
* io.javaoperatorsdk.operator.api.reconciler.UpdateControl} will be available for next
470+
* reconciliation.
472471
*
473-
* <p>The framework can be smart about it and make such guarantees, but this can be done
472+
* <p>If by default you update the primary resource from reconciler regardless if you use {@link
473+
* io.javaoperatorsdk.operator.api.reconciler.UpdateControl} or directly the Kubernetes client, it
474+
* is not guaranteed that for the next reconciliation will receive the most up-to-date resource.
475+
* This is a consequence of how the informers work in Operator pattern.
476+
*
477+
* <p>However, the framework can be smart about it and make such guarantees, but this can be done
474478
* absolutely reliably only if it bends some rules of the Kubernetes API contract. Thus, if we
475479
* parse the resourceVersion of a primary resource as an integer and compare it with the version
476480
* of the resource in the cache. Note that this is a gray area, since with default setup Etcd
477481
* guarantees such monotonically increasing resource versions. But since it is still bending the
478-
* rules by default, this feature is turned off, and work only if {@link
482+
* rules by default, this feature is turned off, and requires {@link
479483
* #parseResourceVersionsForEventFilteringAndCaching} is also set to true.
480484
*
481485
* <p>See also {@link io.javaoperatorsdk.operator.api.reconciler.PrimaryUpdateAndCacheUtils}
482486
*
483487
* @return if the framework should cache the updated resource for next reconciliation
484488
*/
485-
default boolean cacheUpdatedResourcesViaUpdateControl() {
489+
default boolean guaranteeUpdatedPrimaryIsAvailableForNextReconciliation() {
486490
return false;
487491
}
488492

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public ConfigurationServiceOverrider withCloneSecondaryResourcesWhenGettingFromC
189189
return this;
190190
}
191191

192-
public ConfigurationServiceOverrider withCacheUpdatedResourcesViaUpdateControl(boolean value) {
192+
public ConfigurationServiceOverrider withGuaranteeUpdatedPrimaryIsAvailableForNextReconciliation(
193+
boolean value) {
193194
this.cacheUpdatedResourcesViaUpdateControl = value;
194195
return this;
195196
}
@@ -336,10 +337,10 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
336337
}
337338

338339
@Override
339-
public boolean cacheUpdatedResourcesViaUpdateControl() {
340+
public boolean guaranteeUpdatedPrimaryIsAvailableForNextReconciliation() {
340341
return overriddenValueOrDefault(
341342
cacheUpdatedResourcesViaUpdateControl,
342-
ConfigurationService::cacheUpdatedResourcesViaUpdateControl);
343+
ConfigurationService::guaranteeUpdatedPrimaryIsAvailableForNextReconciliation);
343344
}
344345
};
345346
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/ReconciliationDispatcher.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,21 @@ public CustomResourceFacade(
430430
this.fieldManager = configuration.fieldManager();
431431
this.cacheUpdatedResources =
432432
configuration
433-
.getConfigurationService()
434-
.previousAnnotationForDependentResourcesEventFiltering()
435-
&& configuration.getConfigurationService().cacheUpdatedResourcesViaUpdateControl();
433+
.getConfigurationService()
434+
.guaranteeUpdatedPrimaryIsAvailableForNextReconciliation();
435+
436436
this.cloner = cloner;
437437
this.controllerEventSource = controllerEventSource;
438+
439+
if (cacheUpdatedResources
440+
&& !configuration
441+
.getConfigurationService()
442+
.previousAnnotationForDependentResourcesEventFiltering()) {
443+
throw new OperatorException(
444+
"guaranteeUpdatedPrimaryIsAvailableForNextReconciliation is set to true, but"
445+
+ " previousAnnotationForDependentResourcesEventFiltering is set to false, set this"
446+
+ " flag also to true if you want to use this feature");
447+
}
438448
}
439449

440450
private void cachePrimaryResource(R updatedResource, R previousVersionOfResource) {

0 commit comments

Comments
 (0)