Skip to content

Commit f63af4a

Browse files
committed
improved docs, fixed unit test
1 parent 46bfb80 commit f63af4a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

operator-framework/src/main/java/com/github/containersolutions/operator/processing/EventDispatcher.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ public EventDispatcher(ResourceController<R> controller,
4343
public void handleEvent(Watcher.Action action, R resource) {
4444
log.info("Handling event {} for resource {}", action, resource.getMetadata());
4545
if (action == Watcher.Action.MODIFIED || action == Watcher.Action.ADDED) {
46-
// we don't want to call delete resource if it not contains our finalizer,
47-
// since the resource still can be updates when marked for deletion and contains other finalizers
46+
// Its interesting problem if we should call delete if received event after object is marked for deletion
47+
// but there is not our finalizer. Since it can happen that there are multiple finalizers, also other events after
48+
// we called delete and remove finalizers already. But also it can happen that we did not manage to put
49+
// finalizer into the resource before marked for delete. So for now we will call delete every time, since delete
50+
// operation should be idempotent too, and this way we cover the corner case.
4851
if (markedForDeletion(resource)) {
4952
boolean removeFinalizer = controller.deleteResource(resource, new Context(k8sClient, resourceClient));
5053
if (removeFinalizer && hasDefaultFinalizer(resource)) {

operator-framework/src/test/java/com/github/containersolutions/operator/EventDispatcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ void callsDeleteIfObjectHasFinalizerAndMarkedForDelete() {
8686
* Note that there could be more finalizers. Out of our control.
8787
*/
8888
@Test
89-
void doesNotCallDeleteOnControllerIfMarkedForDeletionButThereIsNoDefaultFinalizer() {
89+
void callDeleteOnControllerIfMarkedForDeletionButThereIsNoDefaultFinalizer() {
9090
markForDeletion(testCustomResource);
9191

9292
eventDispatcher.handleEvent(Watcher.Action.MODIFIED, testCustomResource);
9393

94-
verify(resourceController, never()).deleteResource(eq(testCustomResource), any());
94+
verify(resourceController).deleteResource(eq(testCustomResource), any());
9595
}
9696

9797
@Test

0 commit comments

Comments
 (0)