Skip to content

Fix: include annotations derived from ingress in certificate reconciliation loop - #8734

Open
D3-LucaPiombino wants to merge 2 commits into
cert-manager:masterfrom
D3-LucaPiombino:fix/include-ingress-anno-in-cert-synch
Open

D3-LucaPiombino wants to merge 2 commits into
cert-manager:masterfrom
D3-LucaPiombino:fix/include-ingress-anno-in-cert-synch

Conversation

@D3-LucaPiombino

Copy link
Copy Markdown

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-ingressclassname annotation 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:

  • New Certificates correctly receive the HTTP01 override annotation from the Ingress
  • Existing Certificates do not detect or reconcile drift in these annotations
  • Stale override annotations propagate through issuance (Certificate → CertificateRequest → Order → solver)

Solution:

  1. Added issuerSpecificConfigNeedsUpdate() to detect mutable HTTP01 solver class override annotation drift (scoped to Ingress resources only)
  2. Added annotationNeedsUpdate() helper to centralize annotation drift comparison logic
  3. Extended setIssuerSpecificConfig() to both add and remove override annotations based on current Ingress state
  4. Updated the Certificate update decision logic to include issuer-specific config drift detection
  5. Added regression tests for Ingress annotation changes on existing Certificates

Scope: This fix intentionally targets only mutable HTTP01 solver-routing class override annotations:

  • acme.cert-manager.io/http01-override-ingress-class
  • acme.cert-manager.io/http01-override-ingress-ingressclassname

Other annotations (ingress-name, temporary certificate, Gateway/ListenerSet parent-refs) are outside this scope.


As mentioned in the issue, the code

setIssuerSpecificConfig(crt, ingLike)

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.

@cert-manager-prow cert-manager-prow Bot added the kind/bug Categorizes issue or PR as related to a bug. label Apr 18, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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.

Details

Instructions 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.

@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 18, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sgtcodfish for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 18, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@cert-manager-prow cert-manager-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 18, 2026
@D3-LucaPiombino D3-LucaPiombino changed the title Fix: include annotations derived from ingress in reconciliation loop Fix: include annotations derived from ingress in certificate reconciliation loop Apr 18, 2026

@lunarwhite lunarwhite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. IMO the issues are real and worth fixing:

  1. No drift detection for ingress-shim-managed annotations (http01 override)
  2. setIssuerSpecificConfig called on wrong object on update path

:Async: Tagging @maelvls @hjoshi123 for deeper architectural review here since this touches some subtle behavior in certificate shim.

Comment on lines +526 to +536
// 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)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/controller/certificate-shim/sync.go Resolved
Comment thread pkg/controller/certificate-shim/sync.go Resolved
@D3-LucaPiombino
D3-LucaPiombino force-pushed the fix/include-ingress-anno-in-cert-synch branch from e627a1b to 1981bcd Compare June 6, 2026 12:56
@cert-manager-prow cert-manager-prow Bot added dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. and removed dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Jun 6, 2026
@D3-LucaPiombino
D3-LucaPiombino force-pushed the fix/include-ingress-anno-in-cert-synch branch from 1981bcd to 1c03d07 Compare June 6, 2026 13:00
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Jun 6, 2026
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 4, 2026
D3-LucaPiombino added 2 commits September 7, 2026 11:31
Rename `issuerSpecificConfigNeedsUpdate` to `shimAnnotationsNeedsUpdate` and inline annotation drift detection

Signed-off-by: D3-LucaPiombino <[email protected]>
@D3-LucaPiombino
D3-LucaPiombino force-pushed the fix/include-ingress-anno-in-cert-synch branch from 1c03d07 to a05c6e2 Compare September 7, 2026 09:31
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 7, 2026
@wallrj
wallrj requested a balanced review from Copilot September 7, 2026 12:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +598 to +600
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) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Updates or removal of solver ingress class annotations on ingresses are not propagated to existing certificates

3 participants