Skip to content

Commit f917aaa

Browse files
committed
cache update improvements
1 parent a17ec3b commit f917aaa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/DefaultEventHandler.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import io.fabric8.kubernetes.client.CustomResource;
5+
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl;
56
import io.javaoperatorsdk.operator.processing.event.*;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
@@ -103,13 +104,18 @@ void eventProcessingFinished(ExecutionScope executionScope, PostExecutionControl
103104
* If an execution is finished, where we updated a custom resource, but there are other events already buffered for next
104105
* execution we might not get the newest custom resource from CustomResource event source in time. Thus we execute
105106
* the next batch of events but with a non up to date CR. Here we cache the latest CustomResource from the update
106-
* execution so we make sure its already used in the up-comming execution.
107+
* execution so we make sure its already used in the up-coming execution.
107108
*/
108109
private void cacheUpdatedResourceIfChanged(ExecutionScope executionScope, PostExecutionControl postExecutionControl) {
109110
if (postExecutionControl.customResourceUpdatedDuringExecution()) {
111+
110112
CustomResource originalCustomResource = executionScope.getCustomResource();
111113
CustomResource customResourceAfterExecution = postExecutionControl.getUpdatedCustomResource().get();
112-
if (!getVersion(originalCustomResource).equals(getVersion(customResourceAfterExecution))) {
114+
CustomResource cachedVersion = this.customResourceCache.getLatestResource(getUID(customResourceAfterExecution)).get();
115+
String originalResourceVersion = getVersion(originalCustomResource);
116+
if (getVersion(cachedVersion).equals(originalResourceVersion) && !originalResourceVersion.equals(getVersion(customResourceAfterExecution))) {
117+
log.debug("Updating custom resource cache from update response for resource uid: {} new version: {} old version: {}",
118+
getUID(originalCustomResource), getVersion(customResourceAfterExecution), getVersion(originalCustomResource));
113119
this.customResourceCache.cacheResource(customResourceAfterExecution);
114120
}
115121
}

0 commit comments

Comments
 (0)