-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support a domain qualified finalizer instead of one that triggers a warning from kubernetes #7273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"slices" | ||
"time" | ||
|
||
acmeapi "golang.org/x/crypto/acme" | ||
|
@@ -92,8 +93,20 @@ func (c *controller) Sync(ctx context.Context, chOriginal *cmacme.Challenge) (er | |
// This finalizer ensures that the challenge is not garbage collected before | ||
// cert-manager has a chance to clean up resources created for the | ||
// challenge. | ||
// | ||
// API Transition | ||
// -- Until UseDomainQualifiedFinalizer is active, we add cmacme.ACMELegacyFinalizer. | ||
// -- When it is active we add cmacme.ACMEDomainQualifiedFinalizer instead. | ||
// | ||
// -- Both finalizers are supported, the flag just controls the one we add. | ||
// | ||
// -- We only need to add a finalizer label if no supported finalizer label is present. | ||
if finalizerRequired(ch) { | ||
ch.Finalizers = append(ch.Finalizers, cmacme.ACMEFinalizer) | ||
finalizer := cmacme.ACMELegacyFinalizer | ||
if utilfeature.DefaultFeatureGate.Enabled(feature.UseDomainQualifiedFinalizer) { | ||
finalizer = cmacme.ACMEDomainQualifiedFinalizer | ||
} | ||
ch.Finalizers = append(ch.Finalizers, finalizer) | ||
return nil | ||
} | ||
|
||
|
@@ -256,14 +269,16 @@ func (c *controller) handleFinalizer(ctx context.Context, ch *cmacme.Challenge) | |
if len(ch.Finalizers) == 0 { | ||
return nil | ||
} | ||
if ch.Finalizers[0] != cmacme.ACMEFinalizer { | ||
if otherFinalizerPresent(ch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic looks odd to me. Why are we just checking the first finalizer now? And I don't think we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code is black magic. There is a model of naming functions to clarify the intent of black magic "comments as code" . The alternative model is to add comments which regularly fall out of sync. I'm guessing about the intent of the current code and trying to generalize it to the case that one or both of the supported finalizers are present. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the need for this logic. Kubernetes will only finalize the resource deletion when all finalizers are gone: https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/. We should only have to care for "our" finalizers. If a foreign controller has added a finalizer, that controller should remove its finalizer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason I can think of is that the ordering would be important, but I doubt that is the case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming the current code is wrong, what should it be doing? Is it trying to see if any other finalizer is in any slot of the list? Or is it trying to see if our finalizer isn't in the list? Or should the logic be removed? The code change here is the closest to the spirit of the current code, but it sure doesn't seem like the current behavior is desired. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, your change matches the current behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @munnerz do you remember why you added this check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would collapse this conditional with the previous one: Exit early if none of our finalizers are present.
Maybe @munnerz remembers why? |
||
log.V(logf.DebugLevel).Info("waiting to run challenge finalization...") | ||
return nil | ||
} | ||
|
||
defer func() { | ||
// call Update to remove the metadata.finalizers entry | ||
ch.Finalizers = ch.Finalizers[1:] | ||
ch.Finalizers = slices.DeleteFunc(ch.Finalizers, func(finalizer string) bool { | ||
return finalizer == cmacme.ACMELegacyFinalizer || finalizer == cmacme.ACMEDomainQualifiedFinalizer | ||
}) | ||
}() | ||
|
||
if !ch.Status.Processing { | ||
|
Uh oh!
There was an error while loading. Please reload this page.