Skip to content

Commit 706d162

Browse files
committed
hardedning obsolete cleanup conditions
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 386e280 commit 706d162

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ private String getLatestResourceVersion(String namespace) {
226226
return managedInformerEventSource.manager().lastSyncResourceVersion(namespace);
227227
}
228228

229-
// todo obsolete is the good word?
230229
/**
231230
* There are (probably) extremely rare circumstances, when we can miss a delete event related to a
232231
* resources: when we create a resource that is deleted right after by third party and the related
@@ -242,11 +241,15 @@ private void checkObsoleteResources() {
242241
while (iterator.hasNext()) {
243242
var e = iterator.next();
244243
if (ReconcilerUtilsInternal.compareResourceVersions(
245-
e.getValue().getMetadata().getResourceVersion(),
246-
getLatestResourceVersion(e.getValue().getMetadata().getNamespace()))
247-
< 0) {
244+
e.getValue().getMetadata().getResourceVersion(),
245+
getLatestResourceVersion(e.getValue().getMetadata().getNamespace()))
246+
< 0
247+
// making sure we have the situation where resource is missing from the cache
248+
&& managedInformerEventSource
249+
.manager()
250+
.get(ResourceID.fromResource(e.getValue()))
251+
.isEmpty()) {
248252
iterator.remove();
249-
// todo test delete event propagation?
250253
managedInformerEventSource.handleEvent(ResourceAction.DELETED, e.getValue(), null, true);
251254
log.debug("Removing obsolete resource with ID: {}", e.getKey());
252255
}

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/informer/TemporaryPrimaryResourceCacheTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@
3434
import static org.awaitility.Awaitility.await;
3535
import static org.junit.jupiter.api.Assertions.assertTrue;
3636
import static org.mockito.ArgumentMatchers.any;
37+
import static org.mockito.ArgumentMatchers.eq;
38+
import static org.mockito.ArgumentMatchers.isNull;
3739
import static org.mockito.Mockito.mock;
40+
import static org.mockito.Mockito.times;
41+
import static org.mockito.Mockito.verify;
3842
import static org.mockito.Mockito.when;
3943

4044
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -339,6 +343,8 @@ void removalOfObsoleteResources() {
339343
() ->
340344
assertThat(temporaryResourceCache.getResourceFromCache(ResourceID.fromResource(tr)))
341345
.isEmpty());
346+
verify(managedInformerEventSource, times(1))
347+
.handleEvent(eq(ResourceAction.DELETED), eq(tr), isNull(), eq(true));
342348
}
343349

344350
@Test

0 commit comments

Comments
 (0)