Repository navigation
Treat a NotFound delete as done when cleaning up solver ingresses - #9228
cert-manager-prow[bot] merged 2 commits into
Conversation
Signed-off-by: Arpit Jain <[email protected]>
|
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 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. |
| "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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| if err != nil { | ||
| t.Errorf("error preparing test: %v", err) | ||
| } | ||
| s.testResources[createdIngressKey] = ing |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Both gone. The store was left over from the case I copied.
There was a problem hiding this comment.
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
IsNotFounderrors from ingress deletes incleanupIngressesand 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.
| "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") |
There was a problem hiding this comment.
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.
Signed-off-by: Arpit Jain <[email protected]>
wallrj
left a comment
There was a problem hiding this comment.
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.staticcheckreports 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, whilePartialMetadataObjectsseeds 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]
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
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 Tracked in #9275. /retest [Claude Fable 5] |
|
/cherry-pick release-1.21 |
|
@wallrj: new pull request created: #9278 DetailsIn response to this:
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. |
|
@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. |
Fixes #9223.
cleanupIngressesgets 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 backNotFoundand 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 treatsIsNotFoundon the get as a finished cleanup, so this makes the two branches agree.Other delete errors still go into the aggregate.
cleanupPodsandcleanupServicesrun in the sameCleanUpaggregate 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 aPartialObjectMetadataand 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.
TestCleanupPodsandTestCleanupServicesare new, each with an already-gone case and a delete-fails case. On the first commit the three already-gone cases fail withingresses.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.