Skip to content

Commit 2d6a2a1

Browse files
committed
cache option
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 5d662b8 commit 2d6a2a1

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,17 @@ default boolean previousAnnotationForDependentResourcesEventFiltering() {
457457
* logic, and you want to further minimize the amount of work done / updates issued by the
458458
* operator.
459459
*
460-
* @return if resource version should be parsed (as integer)
461460
* @since 4.5.0
462-
* @return if resource version should be parsed (as integer)
461+
* @return if resourceVersion should be parsed (as integer)
463462
*/
464463
default boolean parseResourceVersionsForEventFilteringAndCaching() {
465464
return false;
466465
}
467466

467+
default boolean cacheUpdatedResourcesViaUpdateControl() {
468+
return false;
469+
}
470+
468471
/**
469472
* {@link io.javaoperatorsdk.operator.api.reconciler.UpdateControl} patch resource or status can
470473
* either use simple patches or SSA. Setting this to {@code true}, controllers will use SSA for

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class ConfigurationServiceOverrider {
4040
private Boolean parseResourceVersions;
4141
private Boolean useSSAToPatchPrimaryResource;
4242
private Boolean cloneSecondaryResourcesWhenGettingFromCache;
43+
private Boolean cacheUpdatedResourcesViaUpdateControl;
4344

4445
@SuppressWarnings("rawtypes")
4546
private DependentResourceFactory dependentResourceFactory;
@@ -188,6 +189,11 @@ public ConfigurationServiceOverrider withCloneSecondaryResourcesWhenGettingFromC
188189
return this;
189190
}
190191

192+
public ConfigurationServiceOverrider withCacheUpdatedResourcesViaUpdateControl(boolean value) {
193+
this.cacheUpdatedResourcesViaUpdateControl = value;
194+
return this;
195+
}
196+
191197
public ConfigurationService build() {
192198
return new BaseConfigurationService(original.getVersion(), cloner, client) {
193199
@Override
@@ -328,6 +334,13 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
328334
cloneSecondaryResourcesWhenGettingFromCache,
329335
ConfigurationService::cloneSecondaryResourcesWhenGettingFromCache);
330336
}
337+
338+
@Override
339+
public boolean cacheUpdatedResourcesViaUpdateControl() {
340+
return overriddenValueOrDefault(
341+
cacheUpdatedResourcesViaUpdateControl,
342+
ConfigurationService::cacheUpdatedResourcesViaUpdateControl);
343+
}
331344
};
332345
}
333346
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ static class CustomResourceFacade<R extends HasMetadata> {
416416
private final boolean useSSA;
417417
private final String fieldManager;
418418
private final Cloner cloner;
419-
private final boolean previousAnnotationForDependentResourcesEventFiltering;
419+
private final boolean cacheUpdatedResources;
420+
420421
private final ControllerEventSource<R> controllerEventSource;
421422

422423
public CustomResourceFacade(
@@ -427,16 +428,17 @@ public CustomResourceFacade(
427428
this.resourceOperation = resourceOperation;
428429
this.useSSA = configuration.getConfigurationService().useSSAToPatchPrimaryResource();
429430
this.fieldManager = configuration.fieldManager();
430-
this.previousAnnotationForDependentResourcesEventFiltering =
431+
this.cacheUpdatedResources =
431432
configuration
432-
.getConfigurationService()
433-
.previousAnnotationForDependentResourcesEventFiltering();
433+
.getConfigurationService()
434+
.previousAnnotationForDependentResourcesEventFiltering()
435+
&& configuration.getConfigurationService().cacheUpdatedResourcesViaUpdateControl();
434436
this.cloner = cloner;
435437
this.controllerEventSource = controllerEventSource;
436438
}
437439

438440
private void cachePrimaryResource(R updatedResource, R previousVersionOfResource) {
439-
if (previousAnnotationForDependentResourcesEventFiltering) {
441+
if (cacheUpdatedResources) {
440442
controllerEventSource.handleRecentResourceUpdate(
441443
ResourceID.fromResource(updatedResource), updatedResource, previousVersionOfResource);
442444
}

0 commit comments

Comments
 (0)