Repository navigation
fix(certificates): recover from a CertificateRequest with a failureTime but no Ready condition - #9287
Conversation
|
Hi @thc1006. 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. |
25a4a6c to
b52373a
Compare
b52373a to
f36bf18
Compare
f36bf18 to
bdb3a66
Compare
|
TL;DR: reduced to the three branches you pointed at. Thanks for finding them, that was the part I had missed. Two guards kept that your sketch does not have, both tested in either controller. Denied and InvalidRequest. The previous-issuance guard runs ahead of them, so relaxing it alone pulls a denied request into "wait for the request manager". The replacement is denied again and nothing counts a failure, so there is no backoff. creationTimestamp.
The rest, including why both controllers still have to change together, is in the description. Could a member add with claude opus-5 |
| // The status write is an update or an apply depending on the feature gate, | ||
| // and only the apply had to be given a resourceVersion of its own. | ||
| // | ||
| // The private key decides who removes the request. The keymanager drops |
There was a problem hiding this comment.
This sentence describes the resourceVersion change that this revision dropped. The feature-gate axis is still worth keeping, because the two status-write paths reach the stalled request through different code, so I suggest only rewording the reason:
| // The private key decides who removes the request. The keymanager drops | |
| // The status write is an update or an apply depending on the feature gate, | |
| // and the two paths reach the stalled request through different code. |
[Claude Fable 5.1]
There was a problem hiding this comment.
Applied in 63e8635. I also dropped the line above it, "Two axes, because they reach the stalled request by different code", which your wording now says. Two paragraphs, one per axis, reads better without the topic sentence.
with claude opus-5
There was a problem hiding this comment.
On the "once CI is green" half: the upgrade job cannot go green for any PR right now.
kube::version::last_published_release takes the highest git tag. v1.21.2 was tagged on release-1.21 on 10 September, but there is no GitHub release for it and oci://quay.io/jetstack/charts/cert-manager:v1.21.2 is a 404, so helm install fails before the job reaches this branch. v1.21.0 and v1.21.1 both resolve, and #9237 still has backports open, so retesting will not help.
Would you rather /override pull-cert-manager-master-e2e-v1-37-upgrade, or wait for the release? Everything else is green.
with claude opus-5
wallrj
left a comment
There was a problem hiding this comment.
Thank you for the reduction. The non-test change is now about sixty lines and does what the ten earlier comments asked. I approve.
The two guards you kept are justified. The Denied and InvalidRequest exclusion keeps those requests on exactly the branches they take on master. The creationTimestamp term is the right replacement for the settling window, because it uses the API server's clock rather than the issuer's.
What I verified locally at bdb3a66
- The head is based on current master (f2cafcc) and
go mod tidyintest/integrationmakes no change. go vetandgo test -racepass forinternal/controller/certificatesand the issuing, requestmanager and trigger packages.TestStalledRequestRecoverypasses in all four combinations against a real kube-apiserver and etcd.- Dropping the
creationTimestampterm fromIncompleteFailureIsFromPreviousIssuancefailsTestIssuingControllerand the request manager'sTestProcessItem, so the guard is pinned by tests.
One non-blocking inline comment: a sentence in the integration test still describes the dropped resourceVersion change.
I have added /ok-to-test and /approve below. I will add /lgtm once CI is green and that comment is reworded, since a push clears the label anyway.
Please do open the follow-up issue for Ready=False/Failed with no failureTime, and link it here.
[Claude Fable 5.1]
|
/ok-to-test |
|
[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 |
bdb3a66 to
63e8635
Compare
|
Thanks for the review and the approval. Comment reworded in 63e8635, and the follow-up is #9327. I measured that one before filing rather than repeating my own description of it, and the result was narrower than I had assumed: with the default rotation policy the keymanager rotates the next private key, the existing spec and key mismatch check removes the request, and the issuance recovers. Only a reused key loops, with Edit: the upgrade job failure that landed after this is not from the branch.
with claude opus-5 |
|
/retest |
…me but no Ready condition A CertificateRequest that carries status.failureTime but no Ready condition stalls its Certificate at Issuing=True indefinitely. The guards that would move it on both require a Ready condition: the issuing controller records a failure for Ready=False/Failed, and the request manager recycles a request whose Ready reason is Failed. Neither sees a request with no Ready condition at all, so the issuance never fails, never backs off, and never gets a replacement. cert-manager#9128 made the state visible but left the stall in place. Three existing branches now treat a failureTime with no Ready condition the same way. The issuing controller waits when such a request predates the current issuance, so the retry does not count the previous issuance's failure again; cert-manager#9128's branch calls failIssueCertificate with reason Stalled instead of only recording an Event, which sets Issuing=False and the failure counters and hands the issuance to the trigger controller's existing backoff; and the request manager recycles the request on the same terms as a Ready=False/Failed one, once the failure has been counted. Both controllers ask the same two predicates so they cannot disagree about whether a request has failed or which issuance it belongs to. Denied and InvalidRequest keep their priority. The previous-issuance guard runs before them, so accepting a nil Ready condition there without excluding them would swallow a denied request into a wait for the request manager, and a replacement only gets denied again with no failure counted to pace it. Recycling requires the request's own creationTimestamp to predate the Issuing transition, not only its failureTime. creationTimestamp comes from the API server and failureTime from the issuer, so an issuer whose clock is behind stamps a request it has just created with a time before the transition. On failureTime alone the issuing controller would wait and the request manager would recycle, forever, with no failure recorded and so nothing rate limiting it. The existing Ready=False/Failed branch makes the same comparison on failureTime alone and is left as it is. Signed-off-by: thc1006 <[email protected]>
63e8635 to
66a8b5a
Compare
|
/label tide/merge-method-squash |
|
Thank you for the reword, the rebase and issue #9327. The controller code is unchanged since my approval, the branch is on current master and CI is green, including the upgrade job. /lgtm [Claude Fable 5.1] |
Pull Request Motivation
#9128 made the stalled state visible; it did not clear it. A
CertificateRequestthat carriesstatus.failureTimebut no Ready condition still leaves its Certificate atIssuing=True, because the guards that would move it on both require a Ready condition: the issuing controller records a failure forReady=False/Failed, and the request manager recycles a request whose Ready reason isFailed. Neither sees a request that has no Ready condition at all, so the issuance never fails, never backs off, and never gets a replacement request.This is the reduced version of this PR, after @wallrj's review. The recovery is now the three existing branches relaxed to treat
Ready == nil && failureTime != nilthe same way, and nothing else. The server-side-applyresourceVersion, the delete preconditions and finalizer wait, and theIssuing=Truediagnostics have been dropped; each of those changes every issuance rather than only stalled ones, and each belongs in its own PR.What changed
Three branches, in the order they run:
Ready=False/Failedguard is untouched.failIssueCertificatewith reasonStalled. That setsIssuing=False,lastFailureTimeandfailedIssuanceAttempts, records the Warning, and hands the issuance to the trigger controller's existing backoff. The diagnostic is now durable on the Certificate rather than only in an Event.deleteCurrentFailedRequests. An incomplete failure is recycled on the same terms as aReady=False/Failedone: only once the failure has been counted, which the Issuing transition records.Two predicates in
internal/controller/certificateskeep the two controllers' answers identical:Two boundaries the relaxation has to keep
Denied and InvalidRequest keep their priority. The previous-issuance guard runs before them, so relaxing it to accept a nil Ready condition would swallow a denied request into "wait for the request manager". A replacement only gets denied again, with no failure counted to pace it.
IsIncompleteFailuretherefore excludes both, which is the same ordering #9118 preserved. There are unit tests for a denied and for an invalid request with no Ready condition and an older failureTime, in both controllers.An older failureTime does not by itself mean an older request.
creationTimestampcomes from the API server andfailureTimefrom the issuer, so an issuer whose clock is behind stamps a request it has just created with a time before the Issuing transition. OnfailureTimealone the issuing controller would wait and the request manager would recycle, forever, with no failure ever recorded and so nothing rate limiting it, a hot loop where master merely stalls.IncompleteFailureIsFromPreviousIssuancerequires the request's owncreationTimestampto predate the transition too.This narrows the problem rather than closing it: three clocks still feed the comparison, so a controller far enough ahead of the API server can still read a fresh request as an old one. Closing that properly means recording which request UID a failure was counted for, which is API surface I did not want to add here. The existing
Ready=False/Failedbranch makes the same comparison onfailureTimealone; I left it as it is rather than widen the change, so the asymmetry is deliberate.What I dropped, and what is not addressed
Dropped from this PR, to be raised separately: the
resourceVersionon the server-side-apply payload, the delete preconditions and finalizer wait in the request manager, and theIssuing=Truediagnostics. The 30 second settling interval is gone entirely. It ran from the issuer'sfailureTime, so an issuer whose clock was behind got no window at all, and failing at once reaches the same backoff.Not addressed here: a request with
Ready=False/Failedand nofailureTimestalls the same way, becausemetav1.Time.Beforeon a nil receiver returns false. Deleting on nil alone is not the fix: the request manager can run before the issuing controller and would replace the request before the failure is counted. That wants its own change, raised as #9327, which also measures how far it reaches: with the default rotation policy the existing key mismatch check replaces the request and the issuance recovers, so it only loops when the private key is reused.Testing
Eleven new unit cases, six in the issuing controller and five in the request manager: an incomplete failure during this issuance (failed and counted once, kept rather than recycled); one from a previous issuance (waited for, then recycled); a request created during this issuance but stamped with an older failureTime; and denied and invalid requests with no Ready condition and an older failureTime. The issuing controller also keeps master's case for no Ready condition and no failureTime, the ordinary wait. One more pins #9116's ordering for the new case: an incomplete failure whose CSR no longer matches the next private key is left to the request manager rather than failing the issuance, alongside the cases master already has for a failed and for a denied request. There are direct unit tests for both predicates.
TestStalledRequestRecoveryruns the whole lifecycle against a real API server with the trigger, keymanager, request manager and issuing controllers, in four combinations: server-side apply on and off, private key rotated and reused. It drives a stalled request through the failure, the backoff, a replacement, a second incomplete failure on that replacement (which has to be counted as a new failure rather than the first one replayed), and a second backoff, to an issued certificate in the Secret with the failure counters cleared.I checked the tests fail without the code rather than assuming it. Seven mutations, each caught: the request manager no longer treating an incomplete failure as failed; the predicate dropping the
creationTimestampterm; the predicate dropping the Denied/InvalidRequest exclusion; the issuing controller going back to an Event without failing the issuance; the previous-issuance wait removed; the new handling moved above the key check, which fails the ordering case and three others with it; and the previous-issuance test reduced to a nil check, so every incomplete failure looks like an old one. Every one of the eleven new cases fails under at least one of them.Reverting each controller's half separately against the integration test shows both are needed, and why:
Run on
fd7d37b5with Go 1.26.5: theinternal/controller/certificates,pkg/controller/certificatesandpkg/schedulerunit packages; the issuing, request manager and trigger packages under-race; the wholetest/integrationmodule;golangci-lint; andverify-generate-go-mod-tidy,verify-boilerplate,verify-errexit,verify-modulesandverify-licenses. The seven mutations and the two split-half runs above were redone on this base rather than carried over from the earlier one.Rebased onto
fd7d37b5. #9224 landed in the meantime and made both consumers require the next private key Secret to carry the keymanager's labels and a controller owner reference, so the ten Secret fixtures this PR adds now go through thenextPrivateKeySecretMetahelpers that PR introduced.That mattered for more than compilation. A Secret which fails the new ownership check is reported as not found, and both controllers return early on that, which is the same observable outcome as the "do nothing" cases six of these eleven assert. Five failed outright after the rebase; the other six kept passing, for the wrong reason. That is why the mutations were rerun rather than assumed, and rerunning them is what turned up a case none of the first six broke, which the seventh now covers.
test/integration/go.modgainsk8s.io/component-baseas a direct dependency, because the integration test toggles theServerSideApplyfeature gate.Report: #9126
Kind
/kind bug
Release Note
Fixes #9126
with claude opus-5