Skip to content

Commit 6a543d2

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 9a6c28c commit 6a543d2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.fabric8.kubernetes.client.dsl.MixedOperation;
3333
import io.fabric8.kubernetes.client.informers.ResourceEventHandler;
3434
import io.javaoperatorsdk.operator.OperatorException;
35+
import io.javaoperatorsdk.operator.ReconcilerUtilsInternal;
3536
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
3637
import io.javaoperatorsdk.operator.api.config.Informable;
3738
import io.javaoperatorsdk.operator.api.config.NamespaceChangeable;
@@ -186,14 +187,21 @@ public void handleRecentResourceCreate(ResourceID resourceID, R resource) {
186187

187188
@Override
188189
public Optional<R> get(ResourceID resourceID) {
189-
if (comparableResourceVersions) {
190-
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
191-
if (resource.isPresent()) {
192-
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
193-
return resource;
194-
}
195-
}
190+
// The order of these two lookups matters. If we queried the informer cache first,
191+
// a race condition could occur: we might not find the resource there yet, then
192+
// process an informer event that evicts the temporary resource cache entry. At that
193+
// point the resource would already be present in the informer cache, but we would
194+
// have missed it in both caches during this call.
195+
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
196196
var res = cache.get(resourceID);
197+
if (comparableResourceVersions
198+
&& resource.isPresent()
199+
&& res.filter(
200+
r -> ReconcilerUtilsInternal.compareResourceVersions(r, resource.orElseThrow()) > 0)
201+
.isEmpty()) {
202+
log.debug("Latest resource found in temporary cache for Resource ID: {}", resourceID);
203+
return resource;
204+
}
197205
log.debug(
198206
"Resource not found, or older, in temporary cache. Found in informer cache {}, for"
199207
+ " Resource ID: {}",

0 commit comments

Comments
 (0)