Skip to content

Commit ddd7c42

Browse files
authored
fix: processor issue with cleanup resources (#2049)
* fix: processor issue with cleanup resources if leader election not running delete event was not cleaning up state Signed-off-by: Attila Mészáros <[email protected]> * revert small change Signed-off-by: Attila Mészáros <[email protected]> --------- Signed-off-by: Attila Mészáros <[email protected]>
1 parent 2aa8dfe commit ddd7c42

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventProcessor.java

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public synchronized void handleEvent(Event event) {
9797
metrics.receivedEvent(event, metricsMetadata);
9898
handleEventMarking(event, state);
9999
if (!this.running) {
100+
if (state.deleteEventPresent()) {
101+
cleanupForDeletedEvent(state.getId());
102+
}
100103
// events are received and marked, but will be processed when started, see start() method.
101104
log.debug("Skipping event: {} because the event processor is not started", event);
102105
return;

Diff for: operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/EventProcessorTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,21 @@ void executionOfReconciliationShouldNotStartIfProcessorStopped() throws Interrup
452452
.handleExecution(any());
453453
}
454454

455+
@Test
456+
void cleansUpForDeleteEventEvenIfProcessorNotStarted() {
457+
ResourceID resourceID = new ResourceID("test1", "default");
458+
459+
eventProcessor =
460+
spy(new EventProcessor(controllerConfiguration(null, rateLimiterMock),
461+
reconciliationDispatcherMock,
462+
eventSourceManagerMock, null));
463+
464+
eventProcessor.handleEvent(prepareCREvent(resourceID));
465+
eventProcessor.handleEvent(new ResourceEvent(ResourceAction.DELETED, resourceID, null));
466+
eventProcessor.handleEvent(prepareCREvent(resourceID));
467+
// no exception thrown
468+
}
469+
455470
private ResourceID eventAlreadyUnderProcessing() {
456471
when(reconciliationDispatcherMock.handleExecution(any()))
457472
.then(

0 commit comments

Comments
 (0)