AmitKumarDas / Decisions

Apache License 2.0
10 stars 3 forks source link

K8s: From Slack - Ordering of finalizers #236

Open AmitKumarDas opened 4 years ago

AmitKumarDas commented 4 years ago

Question

Is there any guidance or documentation on the order in which finalizers should be
processed when you’re writing a controller? @liggitt @deads2k

Answer

deads2k  6 hours ago
there is no ordering guarantee.  Finalizers are free to self-organize if they wish
liggitt  6 hours ago
Finalizers are free to self-organize if they wish either explicitly, by looking at 
other finalizers, or generically, by waiting for some attribute on the object to 
flip to a state that allows them to proceed (edited) 
ncdc  6 hours ago
yeah, that’s what i thought. i could have sworn i read something somewhere several
 years ago that suggested that code handling finalizers should only process a 
finalizer if it’s the 1st in the array
deads2k  6 hours ago
back when we first created them, we debated what to do, but ultimately determined
 that we didn't need to be restrictive.
ncdc  6 hours ago
yeah, it’s not like you can force people to do that in their own code
 :slightly_smiling_face:
liggitt  6 hours ago
https://kubernetes.slack.com/archives/C0EG7JC6T/p1513782528000652
liggitt
finalizers run whenever a controller processes them…
Right, but order can be important, so I think the guidance is that that should
 process when theirs is first in the list
liggitt  6 hours ago
https://kubernetes.slack.com/archives/C0EG7JC6T/p1513869198000022
ncdc
@liggitt re finalizers[0], i can’t find any code that only processes a finalizer 
iff it’s the first element in the slice
munnerz  4 hours ago
FWIW, my own controller goes for the "only if first" approach, probably 
because I too recall seeing that discussion. Perhaps it's worth explicitly 
calling out that they can run in any order somewhere :slightly_smiling_face:
deads2k  4 hours ago
Yeah, we've run in parallel since before 1.0 was released.  There is no functional 
reason to enforce order and doing so introduces risks of bad dependencies 
between them. I see forcing ordering as very risky in a multi-actor world and 
parallel as the safer choice
liggitt  4 hours ago
yeah, that wouldn't pair well with my "only if last" finalizer ;-)
liggitt  4 hours ago
gating on presence of another finalizer you have first-hand knowledge of and 
know you want to go after, or on an attribute of the object that indicates your 
work shouldn't be done yet is all I'd recommend