Skip to content

fix(certificates): recover from a CertificateRequest with a failureTime but no Ready condition - #9287

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
thc1006:fix/9126-stalled-request-recovery
Sep 29, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
thc1006:fix/9126-stalled-request-recovery

Conversation

@thc1006

@thc1006 thc1006 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Motivation

#9128 made the stalled state visible; it did not clear it. A CertificateRequest that carries status.failureTime but no Ready condition still leaves its Certificate at Issuing=True, because 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 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 != nil the same way, and nothing else. The server-side-apply resourceVersion, the delete preconditions and finalizer wait, and the Issuing=True diagnostics 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:

  1. issuing, previous-issuance guard. A new adjacent branch waits when an incomplete failure predates the current issuance, so the retry the trigger controller has just started does not count the previous issuance's failure a second time. The existing Ready=False/Failed guard is untouched.
  2. issuing, fix(issuing): surface stalled CertificateRequest with failureTime but no Ready condition #9128's branch. Instead of only recording an Event, it calls the existing failIssueCertificate with reason Stalled. That sets Issuing=False, lastFailureTime and failedIssuanceAttempts, 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.
  3. request manager, deleteCurrentFailedRequests. An incomplete failure is recycled on the same terms as a Ready=False/Failed one: only once the failure has been counted, which the Issuing transition records.

Two predicates in internal/controller/certificates keep the two controllers' answers identical:

IsIncompleteFailure(req) bool
IncompleteFailureIsFromPreviousIssuance(req, issuing) bool

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. IsIncompleteFailure therefore 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. 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 Issuing transition. On failureTime alone 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. IncompleteFailureIsFromPreviousIssuance requires the request's own creationTimestamp to 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/Failed branch makes the same comparison on failureTime alone; 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 resourceVersion on the server-side-apply payload, the delete preconditions and finalizer wait in the request manager, and the Issuing=True diagnostics. The 30 second settling interval is gone entirely. It ran from the issuer's failureTime, 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/Failed and no failureTime stalls the same way, because metav1.Time.Before on 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.

TestStalledRequestRecovery runs 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 creationTimestamp term; 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:

  • request manager on master, issuing fixed: only the reused private key cases fail. With the default rotation policy the keymanager gives the next issuance a new key, the stalled request no longer matches it, and the request manager's existing key-mismatch check removes it before the recycling path is reached.
  • issuing on master, request manager fixed: all four fail with "the issuance was never failed". Nothing records the failure, so no backoff and no new issuance.

Run on fd7d37b5 with Go 1.26.5: the internal/controller/certificates, pkg/controller/certificates and pkg/scheduler unit packages; the issuing, request manager and trigger packages under -race; the whole test/integration module; golangci-lint; and verify-generate-go-mod-tidy, verify-boilerplate, verify-errexit, verify-modules and verify-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 the nextPrivateKeySecretMeta helpers 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.mod gains k8s.io/component-base as a direct dependency, because the integration test toggles the ServerSideApply feature gate.

Report: #9126

Kind

/kind bug

Release Note

Fixed an issuance that could stall indefinitely when an issuer sets `status.failureTime` on a CertificateRequest without a `Ready` condition. Such a request is now treated as a failure: the issuance is failed with reason `Stalled`, retried under the existing exponential backoff, and the CertificateRequest is replaced on the next attempt.

Fixes #9126

with claude opus-5

@cert-manager-prow cert-manager-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 6, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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 /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 size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. area/testing Issues relating to testing labels Sep 6, 2026
@thc1006
thc1006 force-pushed the fix/9126-stalled-request-recovery branch 9 times, most recently from 25a4a6c to b52373a Compare September 7, 2026 16:41
@thc1006
thc1006 force-pushed the fix/9126-stalled-request-recovery branch from b52373a to f36bf18 Compare September 10, 2026 08:46
@cert-manager-prow cert-manager-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 10, 2026
@thc1006
thc1006 force-pushed the fix/9126-stalled-request-recovery branch from f36bf18 to bdb3a66 Compare September 10, 2026 09:02
@cert-manager-prow cert-manager-prow Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 10, 2026
@thc1006

thc1006 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

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. IsIncompleteFailure excludes both, keeping the ordering from #9118.

creationTimestamp. failureTime comes from the issuer, so a clock running behind stamps a fresh request with a time before the transition. On failureTime alone the issuing controller waits while the request manager recycles, round after round, with no failure recorded to pace it. Today that stalls; without the guard it spins. The existing Ready=False/Failed branch still compares failureTime alone and I left it as it is.

Ready=False/Failed with no failureTime is not in here. Deleting on nil would let the request manager replace the request before the failure is recorded, so I will raise it separately.

The rest, including why both controllers still have to change together, is in the description.

Could a member add /ok-to-test?

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

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

Suggested change
// 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]

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.

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

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.

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

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 tidy in test/integration makes no change.
  • go vet and go test -race pass for internal/controller/certificates and the issuing, requestmanager and trigger packages.
  • TestStalledRequestRecovery passes in all four combinations against a real kube-apiserver and etcd.
  • Dropping the creationTimestamp term from IncompleteFailureIsFromPreviousIssuance fails TestIssuingController and the request manager's TestProcessItem, 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]

@wallrj

wallrj commented Sep 10, 2026

Copy link
Copy Markdown
Member

/ok-to-test
/approve

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 10, 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 10, 2026
@thc1006
thc1006 force-pushed the fix/9126-stalled-request-recovery branch from bdb3a66 to 63e8635 Compare September 10, 2026 15:49
@thc1006

thc1006 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

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 failedIssuanceAttempts climbing on the same object. The issue says that and gives the numbers.

Edit: the upgrade job failure that landed after this is not from the branch. bdb3a66 and 63e8635 differ only by a comment in an integration test, and the job fails before it reaches any of that, at the helm install of the version it upgrades from:

Error: failed to perform "FetchReference" on source: quay.io/jetstack/charts/cert-manager:v1.21.2: not found

verify-upgrade.sh picks that version from git tags. v1.21.2 is tagged, but its chart is a 404 on quay while #9237 is open; v1.21.0 and v1.21.1 both resolve. The job will do this for any PR until the chart is published, so I would rather not /retest into it. Happy to once the release lands, or to pin UPGRADE_TEST_INITIAL_RELEASE if you would prefer a green run sooner.

with claude opus-5

@thc1006

thc1006 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@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 27, 2026
…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]>
@thc1006
thc1006 force-pushed the fix/9126-stalled-request-recovery branch from 63e8635 to 66a8b5a Compare September 29, 2026 08:35
@cert-manager-prow cert-manager-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 29, 2026
@wallrj

wallrj commented Sep 29, 2026

Copy link
Copy Markdown
Member

/label tide/merge-method-squash

@cert-manager-prow cert-manager-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 29, 2026
@wallrj

wallrj commented Sep 29, 2026

Copy link
Copy Markdown
Member

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]

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Sep 29, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit eced78c into cert-manager:master Sep 29, 2026
6 checks passed
@thc1006
thc1006 deleted the fix/9126-stalled-request-recovery branch September 29, 2026 15:52
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/testing Issues relating to testing 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/XL Denotes a PR that changes 500-999 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.

Issuing stalls silently when a CertificateRequest has a failureTime but no Ready condition

2 participants