Skip to content

Commit 322c815

Browse files
committed
comments for implementation
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent ad1941b commit 322c815

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,12 @@ private Stream<R> mergeWithWithTempCacheResources(
300300
if (!comparableResourceVersions || temporaryResourceCache.isEmpty()) {
301301
return stream;
302302
}
303-
304303
var allTempResources = temporaryResourceCache.getResources();
305304
Map<ResourceID, R> tempResources;
306305
if (namespace == null && predicate == null) {
307306
tempResources = new HashMap<>(allTempResources);
308307
} else {
308+
// filtering the temp cache according the user input (predicate, namespace)
309309
tempResources =
310310
allTempResources.entrySet().stream()
311311
.filter(
@@ -322,17 +322,19 @@ private Stream<R> mergeWithWithTempCacheResources(
322322
})
323323
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
324324
}
325-
326325
if (tempResources.isEmpty()) {
327326
return stream;
328327
}
329-
330328
var upToDateList =
331329
stream
332330
.map(
333331
r -> {
334332
var resourceID = ResourceID.fromResource(r);
333+
// removing the id from the related temp resources
334+
// this is important so we can detect ghost resources:
335+
// all that remains is ghost resource
335336
var tempResource = tempResources.remove(resourceID);
337+
// using the latest version
336338
if (tempResource != null
337339
&& ReconcilerUtilsInternal.compareResourceVersions(tempResource, r) > 0) {
338340
return tempResource;
@@ -341,17 +343,18 @@ private Stream<R> mergeWithWithTempCacheResources(
341343
})
342344
.toList();
343345
Stream<R> tempResourceStream;
346+
// ghost resource handling
344347
if (indexName != null && indexKey != null) {
345348
var indexer = indexers.get(indexName);
346349
if (indexer == null) {
347350
throw new IllegalArgumentException("Indexer not found for: " + indexName);
348351
}
352+
// we check if the ghost resource is part of the index
349353
tempResourceStream =
350354
tempResources.values().stream().filter(r -> indexer.apply(r).contains(indexKey));
351355
} else {
352356
tempResourceStream = tempResources.values().stream();
353357
}
354-
355358
return Stream.concat(tempResourceStream, upToDateList.stream());
356359
}
357360

0 commit comments

Comments
 (0)