Repository navigation
Fix: include annotations derived from ingress in certificate reconciliation loop - #8734
D3-LucaPiombino wants to merge 2 commits into
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @D3-LucaPiombino. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
lunarwhite
left a comment
There was a problem hiding this comment.
Thanks for your contribution. IMO the issues are real and worth fixing:
- No drift detection for ingress-shim-managed annotations (http01 override)
setIssuerSpecificConfigcalled on wrong object on update path
:Async: Tagging @maelvls @hjoshi123 for deeper architectural review here since this touches some subtle behavior in certificate shim.
| // Only re-apply issuer-specific config for Ingress resources on the | ||
| // update path. setIssuerSpecificConfig also sets Gateway/ListenerSet | ||
| // parent-ref annotations, and calling it unconditionally here would | ||
| // inject those annotations onto existing Certificates that do not | ||
| // already have them, changing Gateway/ListenerSet update semantics in | ||
| // ways that are outside the scope of this fix. | ||
| // Note: on the creation path (above) it is correctly called for all | ||
| // ingress-like types. | ||
| if _, ok := ingLike.(*networkingv1.Ingress); ok { | ||
| setIssuerSpecificConfig(updateCrt, ingLike) | ||
| } |
There was a problem hiding this comment.
I'm inclined to agree setIssuerSpecificConfig called on wrong object on update path is a latent issue. The annotations set by it on crt were silently discarded on the update path.
But I'm just worried about adding if to scope out Gateway/ListenerSet. If you saw some issues without add filtering here, maybe we should think about where should we fix them exactly?
/cc @hjoshi123 @maelvls who are more experienced in GatewayAPI area.
There was a problem hiding this comment.
But I'm just worried about adding if to scope out Gateway/ListenerSet. If you saw some issues without add filtering here, maybe we should think about where should we fix them exactly?
This is is also what I was worried about as I am not able to properly test that code path.
e627a1b to
1981bcd
Compare
1981bcd to
1c03d07
Compare
Signed-off-by: D3-LucaPiombino <[email protected]>
Rename `issuerSpecificConfigNeedsUpdate` to `shimAnnotationsNeedsUpdate` and inline annotation drift detection Signed-off-by: D3-LucaPiombino <[email protected]>
1c03d07 to
a05c6e2
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The annotation-preservation and server-side-apply removal issues must be resolved before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes reconciliation of HTTP-01 ingress-class overrides on existing shim-managed Certificates.
Changes:
- Detects override annotation drift.
- Updates or removes stale overrides.
- Adds regression tests for both override forms.
Required fixes:
- Critical: Preserve overrides copied through
ExtraCertificateAnnotations; deriving state only from dedicated ingress annotations can delete them. - Moderate: Ensure server-side apply reliably removes stale overrides, with an SSA regression test.
File summaries
| File | Description |
|---|---|
pkg/controller/certificate-shim/sync.go |
Adds HTTP-01 override annotation reconciliation. |
pkg/controller/certificate-shim/sync_test.go |
Tests override updates and removals. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| annotationDrifted := func(desiredAnnotations map[string]string, desiredKey string, existingAnnotations map[string]string, existingKey string) bool { | ||
| desiredValue, desiredPresent := desiredAnnotations[desiredKey] | ||
| desiredHasValue := desiredPresent && desiredValue != "" |
| } | ||
|
|
||
| if !certNeedsUpdate(existingCrt, crt) { | ||
| if !certNeedsUpdate(existingCrt, crt) && !shimAnnotationsNeedsUpdate(existingCrt, ingLike) { |
Pull Request Motivation
This PR fixes a bug where ingress-shim does not reconcile existing Certificate HTTP01 ingress class override annotations when the source Ingress annotation changes.
Related Issue: Resolves #8733
During ingress controller migrations (e.g., nginx → apisix), if the Ingress
acme.cert-manager.io/http01-ingress-ingressclassnameannotation is updated, existing managed Certificates were not updated to reflect the change. This caused renewals to continue routing to the old ingress controller, resulting in HTTP-01 challenge failures.Problem:
Solution:
issuerSpecificConfigNeedsUpdate()to detect mutable HTTP01 solver class override annotation drift (scoped to Ingress resources only)annotationNeedsUpdate()helper to centralize annotation drift comparison logicsetIssuerSpecificConfig()to both add and remove override annotations based on current Ingress stateScope: This fix intentionally targets only mutable HTTP01 solver-routing class override annotations:
acme.cert-manager.io/http01-override-ingress-classacme.cert-manager.io/http01-override-ingress-ingressclassnameOther annotations (ingress-name, temporary certificate, Gateway/ListenerSet parent-refs) are outside this scope.
As mentioned in the issue, the code
cert-manager/pkg/controller/certificate-shim/sync.go
Line 526 in e654879
from what i can tell originally did nothing.
Fixing only that caused tests related to gateway to break.
Hence the reason why that call is now guarded.
Since I am not sure about the original intent, i cannot also be sure if this is now correct or not.
The tests are green, but an expert pair of eyes is probably more effective here.
Note
DISCAIMER
This was built with the help of copilot.
I am not a go developer, this is just intended as a mean to provide a starting point as I really appreciated the work everyone is doing here and wanted to at least try to contribute something instead of simply complaining :)
I did multiple iterations to steer copilot to keep the scope as focused/tight as possible though and to respect the existing way in which the rest of the code is written.
I believe that there are better more elegant solutions to this, i tried some but those had a larger footprint and as mentioned, i wanted to keep this small and focused.
I am not sure what other side effects this might have as I honestly did not have the required knowledge of the codebase to make that assertion.
If this is completely misplaced or there are reason for the current behaviour, feel free to reject/close this.
I understand that the time available for reviewing external contributions is limited.
Kind
/kind bug
Release Note
Fixed ingress-shim not reconciling existing Certificate HTTP01 ingress class override annotations when the source Ingress annotation changes.