Skip to content

Commit c47a551

Browse files
authored
improve: primary to secondary index edge case for dynamic mapper changes (#2246)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 37eb90b commit c47a551

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ public synchronized void onDelete(R resource) {
3333
primaryResources.forEach(
3434
primaryResource -> {
3535
var secondaryResources = index.get(primaryResource);
36-
secondaryResources.remove(ResourceID.fromResource(resource));
37-
if (secondaryResources.isEmpty()) {
38-
index.remove(primaryResource);
36+
// this can be null in just very special cases, like when the secondaryToPrimaryMapper is
37+
// changing dynamically. Like if a list of ResourceIDs mapped dynamically extended in the
38+
// mapper between the onAddOrUpdate and onDelete is called.
39+
if (secondaryResources != null) {
40+
secondaryResources.remove(ResourceID.fromResource(resource));
41+
if (secondaryResources.isEmpty()) {
42+
index.remove(primaryResource);
43+
}
3944
}
4045
});
4146
}

0 commit comments

Comments
 (0)