dotnet-operator-sdk icon indicating copy to clipboard operation
dotnet-operator-sdk copied to clipboard

Ensure that a resource is finalized/reconciled only once

Open NArnott opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe. I'd like to be able to delay a finalizer, similar to how you can "requeue" controller actions. If I want to wait for certain conditions to pass before allowing a finalizer to complete, I thought it would be ok to just await Task.Delay in a loop, but it turns out than more and more calls into the finalizer begin.

Describe the solution you'd like I'd like to be able to return a complete or not complete status inside a finalizer and a requeue time before the finalizer triggers again.

NArnott avatar Dec 23 '21 23:12 NArnott

Hey @NArnott

In theory, the finalizer could just wait for a certain period. The intension would have been to allow the finalizer to wait for certain predicates. So, this seems like a bug that the system does not check which resources are already finalizing.

If it's possible to delay during the finalization method, would that suffice your usecase?

buehler avatar Dec 26 '21 12:12 buehler

Yes, that should also work. Just seems like long waiting loops/task delays inside the finalizer would be an anti-pattern, and make it harder to recover if, say, the controller were to shut down and recover on another instance. Rather, just like all reconcile loops, it would make sense for the finalizer to do it's checks as soon as possible and return complete or not complete just like the other reconcile loops.

NArnott avatar Jan 03 '22 14:01 NArnott

Kind of an anti pattern. The thing is, the same applies to the reconcile loop. When I develop locally and I hit a breakpoint the same resource gets reconciled a second time after the reconnect to the watcher happens. As such, we need some kind of logic that checks if a resource with a particular UID is being reconciled/finalized.

buehler avatar Jan 03 '22 16:01 buehler

I agree that a UID check would be useful for all these cases.

NArnott avatar Jan 03 '22 16:01 NArnott