Skip to content

Commit 3e986ab

Browse files
committed
improvements on edge cases
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 5ea96dc commit 3e986ab

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ public synchronized Optional<GenericResourceEvent> doneEventFilterModify(Resourc
8080
return Optional.empty();
8181
}
8282
var ed = activeUpdates.get(resourceID);
83-
if (!ed.decreaseActiveUpdates()) {
84-
log.debug("Active updates {} for resource id: {}", ed.getActiveUpdates(), resourceID);
83+
if (ed == null || !ed.decreaseActiveUpdates()) {
84+
log.debug(
85+
"Active updates {} for resource id: {}",
86+
ed == null ? null : ed.getActiveUpdates(),
87+
resourceID);
8588
return Optional.empty();
8689
}
8790

@@ -232,7 +235,7 @@ private String getLastSyncResourceVersion(String namespace) {
232235
* explicitly add resources to this cache. Those are cleaned up by this check, which is triggered
233236
* by the informer's onList callback.
234237
*/
235-
public void checkGhostResources() {
238+
public synchronized void checkGhostResources() {
236239
log.debug("Checking for ghost resources.");
237240
var iterator = cache.entrySet().iterator();
238241
while (iterator.hasNext()) {
@@ -247,19 +250,18 @@ public void checkGhostResources() {
247250
e.getKey(),
248251
ns);
249252
iterator.remove();
253+
activeUpdates.remove(e.getKey());
250254
continue;
251255
}
252256
if ((ReconcilerUtilsInternal.compareResourceVersions(
253257
e.getValue().getMetadata().getResourceVersion(), getLastSyncResourceVersion(ns))
254258
< 0)
255259
// making sure we have the situation where resource is missing from the cache
256-
&& managedInformerEventSource
257-
.manager()
258-
.get(ResourceID.fromResource(e.getValue()))
259-
.isEmpty()) {
260+
&& managedInformerEventSource.manager().get(e.getKey()).isEmpty()) {
261+
log.debug("Removing ghost resource with ID: {}", e.getKey());
260262
iterator.remove();
263+
activeUpdates.remove(e.getKey());
261264
managedInformerEventSource.handleEvent(ResourceAction.DELETED, e.getValue(), null, true);
262-
log.debug("Removing ghost resource with ID: {}", e.getKey());
263265
}
264266
}
265267
}

0 commit comments

Comments
 (0)