Skip to content

Commit 5bf2cfc

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent bf0c48a commit 5bf2cfc

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,19 @@ private Stream<R> mergeWithWithTempCacheResources(
359359
return Stream.concat(tempResourceStream, upToDateList.stream());
360360
}
361361

362+
/**
363+
* {@inheritDoc}
364+
*
365+
* <p>This implementation is read-cache-after-write consistent. Keys from the temporary resource
366+
* cache (ghost resources) are included in the result.
367+
*/
362368
@Override
363369
public Stream<ResourceID> keys() {
364-
return cache.keys();
370+
if (!comparableResourceVersions || temporaryResourceCache.isEmpty()) {
371+
return manager().keys();
372+
}
373+
var tempKeys = temporaryResourceCache.getResources().keySet();
374+
return Stream.concat(manager().keys(), tempKeys.stream().filter(k -> !manager().contains(k)));
365375
}
366376

367377
@Override

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,49 @@ void listAddsGhostResources() {
669669
assertThat(result).containsExactlyInAnyOrder(resource, ghostResource);
670670
}
671671

672+
@Test
673+
void keysIncludesGhostResourceKeys() {
674+
var resource = testDeployment();
675+
var ghostResource = testDeployment();
676+
ghostResource.getMetadata().setName("ghost");
677+
678+
var resourceId = ResourceID.fromResource(resource);
679+
var ghostResourceId = ResourceID.fromResource(ghostResource);
680+
681+
when(temporaryResourceCache.getResources()).thenReturn(Map.of(ghostResourceId, ghostResource));
682+
when(temporaryResourceCache.isEmpty()).thenReturn(false);
683+
684+
var mim = mock(InformerManager.class);
685+
when(mim.keys()).thenReturn(Stream.of(resourceId));
686+
when(mim.contains(ghostResourceId)).thenReturn(false);
687+
doReturn(mim).when(informerEventSource).manager();
688+
689+
var result = informerEventSource.keys().toList();
690+
691+
assertThat(result).containsExactlyInAnyOrder(resourceId, ghostResourceId);
692+
}
693+
694+
@Test
695+
void keysDoesNotDuplicateExistingKeys() {
696+
var resource = testDeployment();
697+
var newerResource = testDeployment();
698+
newerResource.getMetadata().setResourceVersion("5");
699+
700+
var resourceId = ResourceID.fromResource(resource);
701+
702+
when(temporaryResourceCache.getResources()).thenReturn(Map.of(resourceId, newerResource));
703+
when(temporaryResourceCache.isEmpty()).thenReturn(false);
704+
705+
var mim = mock(InformerManager.class);
706+
when(mim.keys()).thenReturn(Stream.of(resourceId));
707+
when(mim.contains(resourceId)).thenReturn(true);
708+
doReturn(mim).when(informerEventSource).manager();
709+
710+
var result = informerEventSource.keys().toList();
711+
712+
assertThat(result).containsExactly(resourceId);
713+
}
714+
672715
Deployment testDeployment() {
673716
Deployment deployment = new Deployment();
674717
deployment.setMetadata(new ObjectMeta());

0 commit comments

Comments
 (0)