Skip to content

Commit f621fc9

Browse files
committed
another possible use for comparable resource versions
1 parent a810ac9 commit f621fc9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ public void handleRecentResourceCreate(ResourceID resourceID, R resource) {
133133

134134
@Override
135135
public Optional<R> get(ResourceID resourceID) {
136+
var res = cache.get(resourceID);
136137
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
137-
if (resource.isPresent()) {
138+
if (resource.isPresent() && res.filter(r -> r.getMetadata().getResourceVersion() < resource.get().getMetadata().getResourceVersion()).isPresent()) {
138139
log.debug("Resource found in temporary cache for Resource ID: {}", resourceID);
139140
return resource;
140141
} else {
141142
log.debug(
142143
"Resource not found in temporary cache reading it from informer cache,"
143144
+ " for Resource ID: {}",
144145
resourceID);
145-
var res = cache.get(resourceID);
146146
log.debug("Resource found in cache: {} for id: {}", res.isPresent(), resourceID);
147147
return res;
148148
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryResourceCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public synchronized void putResource(T newResource, String previousResourceVersi
8888
var resourceId = ResourceID.fromResource(newResource);
8989

9090
String latest = managedInformerEventSource.getLastSyncResourceVersion(resourceId.getNamespace()).orElse(null);
91-
if (latest != null && latest >= newResource.getMetadata().getResourceVersion()) {
91+
if (latest != null && latest > newResource.getMetadata().getResourceVersion()) {
9292
log.debug(
9393
"Resource {}: resourceVersion {} is not later than latest {}",
9494
resourceId,

0 commit comments

Comments
 (0)