Skip to content

Treat a NotFound delete as done when cleaning up solver ingresses - #9228

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
arpitjain099:fix/ingress-cleanup-notfound
Sep 4, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
arpitjain099:fix/ingress-cleanup-notfound

Conversation

@arpitjain099

@arpitjain099 arpitjain099 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9223.

cleanupIngresses gets its candidates from the ingress lister, which can be behind the API server. If another actor, or an earlier pass of the same cleanup, already removed a solver ingress, the delete comes back NotFound and that gets folded into the aggregate error even though the ingress is gone, which is the state the cleanup wanted. The named-ingress branch a few lines down already treats IsNotFound on the get as a finished cleanup, so this makes the two branches agree.

Other delete errors still go into the aggregate.

cleanupPods and cleanupServices run in the same CleanUp aggregate and had the identical loop with no NotFound handling, so after review they get the same treatment. Those two read from the metadata informer rather than the typed client, which makes the race easy to reproduce in a test: seed a PartialObjectMetadata and leave the typed client empty, and the lister hands back an object whose delete returns NotFound.

The ingress test case sits beside the existing "should return an error if a delete fails" one and uses the same reactor mechanism. TestCleanupPods and TestCleanupServices are new, each with an already-gone case and a delete-fails case. On the first commit the three already-gone cases fail with ingresses.networking.k8s.io "cm-acme-http-solver-..." not found, error deleting pod: pods "cm-acme-http-solver-fghij" not found, and the service equivalent.

go test ./pkg/issuer/acme/http/... passes.

Fixed HTTP-01 solver cleanup so that a solver ingress, pod or service that has already been deleted no longer fails the cleanup with a NotFound error.

@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. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 31, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @arpitjain099. 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 area/acme Indicates a PR directly modifies the ACME Issuer code area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 31, 2026
@wallrj
wallrj requested a lite review from Copilot September 1, 2026 05:45
Comment thread pkg/issuer/acme/http/ingress_test.go Outdated
"github.com/stretchr/testify/require"
networkingv1 "k8s.io/api/networking/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"

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.

This is a second import of k8s.io/apimachinery/pkg/api/errors — the file already imports it as apierrors on the line above, and the test cases around this one use that alias. staticcheck flags it:

pkg/issuer/acme/http/ingress_test.go:28:2: package "k8s.io/apimachinery/pkg/api/errors" is being imported more than once (ST1019)

ST1019 is not among the excluded checks in .golangci.yaml, so the lint job will fail. Drop this import and use apierrors.NewNotFound(...) in the reactor below.

with claude fable-5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, and the file already had apierrors two lines up. Dropped the second import and the reactor now uses apierrors.NewNotFound(...).


log.V(logf.DebugLevel).Info("deleting ingress resource")
err := s.Client.NetworkingV1().Ingresses(ingress.Namespace).Delete(ctx, ingress.Name, metav1.DeleteOptions{})
if k8sErrors.IsNotFound(err) {

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.

The same race exists one level up: cleanupPods and cleanupServices run in the same CleanUp aggregate, and both have the identical delete-from-lister loop with no NotFound handling (pod.go#L150, service.go#L165). A solver pod or service that is already gone will still fold a NotFound into the aggregate and fail the cleanup, so #9223 is only a third fixed. Worth giving all three loops the same treatment while you are here.

with claude fable-5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed, both loops have the same shape and neither handles NotFound, so all three now do.

The tests took a different form there. getPodsForChallenge and getServicesForChallenge read from the metadata informer, not the typed client, so seeding only a PartialObjectMetadata and leaving the typed client empty reproduces the race directly: the lister returns the object, the delete comes back NotFound. That is TestCleanupPods and TestCleanupServices, each with the already-gone case and a delete-fails case, in the style of TestGetServicesForChallenge. On the previous commit they fail with error deleting pod: pods "cm-acme-http-solver-fghij" not found and the service equivalent.

Comment thread pkg/issuer/acme/http/ingress_test.go Outdated
if err != nil {
t.Errorf("error preparing test: %v", err)
}
s.testResources[createdIngressKey] = ing

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.

Nothing reads testResources in this case (there is no CheckFn), so this store is dead and can go. Likewise Err: false above is the zero value — no other case in this file spells it out.

with claude fable-5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both gone. The store was left over from the case I copied.

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Aligns cleanupIngresses behavior with eventual-consistency realities by treating NotFound deletes of solver ingresses as successful cleanup, preventing spurious aggregate errors when the lister is behind the API server.

Changes:

  • Ignore IsNotFound errors from ingress deletes in cleanupIngresses and continue cleanup.
  • Add a unit test ensuring cleanup does not error when the lister still shows an ingress that has already been deleted from the API server.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/issuer/acme/http/ingress.go Treats NotFound on delete as a successful cleanup state.
pkg/issuer/acme/http/ingress_test.go Adds coverage for the NotFound-on-delete scenario using a fake client reactor.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/issuer/acme/http/ingress_test.go Outdated
"github.com/stretchr/testify/require"
networkingv1 "k8s.io/api/networking/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
if k8sErrors.IsNotFound(err) {
// the lister can be behind the API server, so an ingress that
// is already gone is the state we wanted anyway
log.V(logf.DebugLevel).Info("ingress resource already deleted")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The log in that loop comes from logf.WithRelatedResource(log, ingress) on the line above, so the name and namespace are already on every line it emits, this one included.

@cert-manager-prow cert-manager-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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 Sep 1, 2026

@wallrj wallrj 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 @arpitjain099. The second commit addresses all of the review comments, so I am approving.

I checked out 7650cca and verified:

  • go test ./pkg/issuer/acme/http/... passes, including the new pod and service cases.
  • staticcheck reports nothing. The duplicate import is gone.
  • The new "already gone" tests exercise the NotFound branch for real. The fake clientset is seeded only from KubeObjects, while PartialMetadataObjects seeds only the metadata lister. The delete therefore returns NotFound while the lister still holds the object, which is exactly the race from #9223.

One non-blocking note: the log message in cleanupServices says "failed to delete pod resource". That typo predates this PR and can wait for a follow-up.

/kind bug
/ok-to-test
/lgtm
/approve

[Claude Fable 5]

@cert-manager-prow cert-manager-prow Bot added ok-to-test kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 3, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 3, 2026
@wallrj wallrj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 3, 2026
@wallrj

wallrj commented Sep 4, 2026

Copy link
Copy Markdown
Member

This failure is unrelated to the change. The kind API server stopped responding part way through the run and every spec in flight failed with EOF or connection reset by peer. The same commit had passed this job 14 minutes earlier; tide reran it because master moved.

Tracked in #9275.

/retest

[Claude Fable 5]

@cert-manager-prow
cert-manager-prow Bot merged commit 63e8a65 into cert-manager:master Sep 4, 2026
6 checks passed
@wallrj

wallrj commented Sep 4, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.21

@cert-manager-bot

Copy link
Copy Markdown
Contributor

@wallrj: new pull request created: #9278

Details

In response to this:

/cherry-pick release-1.21

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.

@wallrj wallrj mentioned this pull request Sep 8, 2026
39 of 41 tasks
@wallrj

wallrj commented Sep 11, 2026

Copy link
Copy Markdown
Member

@arpitjain099 This change has been included in v1.21.2, which is now published.

If you are able to install the release and verify that the change works as expected in your environment, that would be much appreciated. Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code area/acme Indicates a PR directly modifies the ACME Issuer code dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cleanupIngresses should ignore Delete NotFound after listing solver ingresses

4 participants