Skip to content

[release-1.21] Surface stalled CertificateRequest with failureTime but no Ready condition - #9324

Closed
wallrj wants to merge 1 commit into
cert-manager:release-1.21from
wallrj:cherry-pick-9128-release-1.21
Closed

wallrj wants to merge 1 commit into
cert-manager:release-1.21from
wallrj:cherry-pick-9128-release-1.21

Conversation

@wallrj

@wallrj wallrj commented Sep 10, 2026

Copy link
Copy Markdown
Member

Pull Request Motivation

Manual cherry-pick of #9128 to release-1.21. Part of #9237.

Prow's /cherry-pick cannot apply it because both changed files conflict on release-1.21. The conflicts are unrelated to this change:

The resulting diff is the #9128 diff with one const alignment change. go test ./pkg/controller/certificates/issuing/... and go vet pass on the branch.

Kind

/kind bug

Release Note

`cert-manager` now emits a Warning `Stalled` Event and an Info-level log on a Certificate when its current CertificateRequest has a `failureTime` set but no `Ready` condition, a state that previously stalled issuance silently.

[Claude Fable 5.1]

… no Ready condition (cert-manager#9128)

* fix(issuing): surface stalled CertificateRequest with failureTime but no Ready condition

Motivation:

A CertificateRequest that has status.failureTime set but no Ready
condition leaves a Certificate stuck at Issuing=True with nothing to
move it along. The issuing controller's wait branch for a nil Ready
condition returns silently at debug level, and the requestmanager
controller only deletes a request whose Ready condition reason is
Failed, so a nil condition is never cleaned up. The in-tree issuers
cannot produce this state (they set failureTime and the Ready
condition in the same status update), but an external issuer or a
partially applied status can, and until then the operator has no
signal beyond one debug-level log line.

Approach:

In the issuing controller's nil-Ready-condition branch, add a
narrower check for req.Status.FailureTime != nil. Only in that
specific sub-case, log at Info level and emit a Warning Event
("Stalled") on the Certificate so the stall is visible via `kubectl
describe certificate` and controller logs at default verbosity. The
common case of a CertificateRequest simply still awaiting a Ready
condition (no failureTime set) is unchanged and stays at debug level,
so this does not add log or event noise to normal in-progress
issuance. Control flow is unchanged in both branches (still returns
nil); this is an observability-only change.

Validation:

Ran `go test -count=1 ./pkg/controller/certificates/issuing/...`
(passes, includes an updated unit test that reproduces the exact
state described in the issue: a CertificateRequest with
status.failureTime set and status.conditions empty). Confirmed the
updated test's event assertion fails without the code change
(`got unexpected events, exp='[Warning Stalled ...]' got='[]'`) and
passes with it, proving the fix. Also ran `go build ./...`,
`go vet ./pkg/controller/certificates/issuing/...`, `gofmt -l` on both
changed files, and `golangci-lint run -c .golangci.yaml
./pkg/controller/certificates/issuing/...` (0 issues). No live cluster
or e2e run was performed; this change has no effect on reconciliation
behaviour (both branches still return nil), so the unit test is
sufficient to prove it.

Report: cert-manager#9126
Signed-off-by: Pujitha Paladugu <[email protected]>

* fix(issuing): address review feedback on stalled-request event

Name the CertificateRequest and add a remediation hint to the Stalled
event message, extract the "Stalled" reason into a package const
matching sibling controllers, and restore test coverage for the
no-failureTime/no-Ready path that was dropped when the Stalled case
was added. Also reword the code comment and adjust the existing
test's failureTime fixture for clarity.

Signed-off-by: Pujitha Paladugu <[email protected]>

* fix(issuing): log stalled-request state at error level

Matches this file's existing convention for should-never-happen
states (see the issuing-condition-missing check above it).

Signed-off-by: Pujitha Paladugu <[email protected]>

---------

Signed-off-by: Pujitha Paladugu <[email protected]>
Co-authored-by: Pujitha Paladugu <[email protected]>
(cherry picked from commit b620f04)

Conflicts resolved by hand: release-1.21 does not have the
reasonTemporaryCertificateFailed const or the key-mismatch test cases
from cert-manager#9116, so only the reasonStalled const and the two test cases from
this change were kept.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
@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. 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. labels Sep 10, 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 joshvanl 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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 10, 2026
@wallrj

wallrj commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

Closing. Nobody has reported hitting this state on 1.21, and #9128 only adds an Event and a log line to a path the in-tree issuers cannot reach. It will ship in v1.22.0. If someone does report the stall on 1.21, we can reopen this; the conflicts are already resolved on the branch.

[Claude Fable 5.1]

@zawachte-m

Copy link
Copy Markdown

We’ve now observed this stall on cert-manager v1.21.2, using the in-tree SelfSigned issuer. Could we reopen this and revisit the backport @wallrj ?

Environment

  • Kubernetes: v1.34.2
  • cert-manager controller, webhook, and cainjector: v1.21.2
  • Controller image: cert-manager-controller:v1.21.2
  • Controller digest: sha256:57bb397c639e0e94184ba67848e5dad04284f24645e521e764a0ee5f5002f286
  • Controller was Ready with zero restarts.
  • Certificate: capi-system/capi-serving-cert
  • Issuer: capi-system/capi-selfsigned-issuer

Logs

On 2026-10-27 at 20:04:26 UTC, these messages appeared within the same second. Excerpts:

20:04:26.344090 selfsigned.go:140
Referenced secret capi-system/capi-serving-cert-zvd85 not found

20:04:26.394524 issuing_controller.go:344
next private key does not match CSR public key, waiting for requestmanager controller

20:04:26.394578 selfsigned.go:201
Error generating certificate template
err="CSR not signed by referenced private key"

20:04:26.546781 trigger_controller.go:212
Backing off from issuance due to previously failed issuance(s).
Issuance will next be attempted at 2026-10-27 21:04:26… +0000 UTC

20:04:26.548885 controller.go:155
Precondition failed:
UID in precondition: 34a4b574-9147-4d13-a46a-95f0868189aa
UID in object meta: e3560b47-34eb-4553-9fd0-04d583b1f072

20:04:26.556069 controller.go:155
certificaterequests.cert-manager.io "capi-serving-cert-1" already exists

Events also recorded two generated temporary key Secrets: capi-serving-cert-6gj5v and capi-serving-cert-zvd85.

Resulting stall

The Certificate remained:

Ready: "False"       # DoesNotExist
Issuing: "False"     # Failed: CSR not signed by referenced private key
failedIssuanceAttempts: 1
lastFailureTime: "2026-10-27T20:04:26Z"

The target Secret, capi-webhook-service-cert, was never created. At 20:35:03 UTC, the CAPI controller pod still reported:

MountVolume.SetUp failed for volume "cert":
secret "capi-webhook-service-cert" not found

This left the controller in ContainerCreating for over 30 minutes, with no webhook endpoints.

@wallrj

wallrj commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Thank you for the detailed report. I will leave this PR closed, because the state you hit is not the one #9128 diagnoses, and backporting it would not have changed anything in your cluster. What you hit is #6331. The fix for that is #9224, which shipped in v1.21.3, with a second fix (#9116) that I propose we backport.

Why #9128 does not apply

#9128 only adds an Event and a log line when a CertificateRequest has a failureTime but no Ready condition. Your CertificateRequest did get a Ready condition: the SelfSigned issuer set it to False with reason Failed ("CSR not signed by referenced private key"). The issuing controller then counted a failed issuance, which is what you see on the Certificate (Issuing: False, failedIssuanceAttempts: 1) and in the "Backing off from issuance" log line. The retry one hour later is the normal failed-issuance backoff, not a permanent stall.

What happened in v1.21.2

Sequence, with links to the v1.21.2 code
  1. The keymanager created two next-private-key Secrets (-6gj5v and -zvd85) because two reconciles ran before the informer cache caught up. The requestmanager signed capi-serving-cert-1 with one of those keys.
  2. The keymanager deleted the Secret the request was signed with, then recreated a Secret under the same name with a new key. In v1.21.2 it reuses the name from status.nextPrivateKeySecretName when it creates a Secret: https://github.com/cert-manager/cert-manager/blob/v1.21.2/pkg/controller/certificates/keymanager/keymanager_controller.go#L369-L393. The "Precondition failed" line shows two UIDs for one name, which is what a delete-and-recreate looks like.
  3. The SelfSigned issuer first saw the Secret missing (https://github.com/cert-manager/cert-manager/blob/v1.21.2/pkg/controller/certificaterequests/selfsigned/selfsigned.go#L137) and then found a Secret with a different key, so it failed the request: https://github.com/cert-manager/cert-manager/blob/v1.21.2/pkg/controller/certificaterequests/selfsigned/selfsigned.go#L196.
  4. The issuing controller in v1.21.2 checks the Failed condition before it checks whether the request's key matches the next private key, so it counted a failed issuance and started the one hour backoff: https://github.com/cert-manager/cert-manager/blob/v1.21.2/pkg/controller/certificates/issuing/issuing_controller.go#L330-L345. The "next private key does not match CSR public key" line in your log is that later check, reached on an earlier pass while the request was still pending.

Fixes

If it happens again on v1.21.3, please attach the CertificateRequest YAML, the Events on the Certificate, and the full text of the two controller.go:155 error lines, which name the object that failed the UID precondition. To recover without waiting for the backoff, run cmctl renew capi-serving-cert -n capi-system.

[Claude Fable 5.1]

@wallrj

wallrj commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

The #9116 backport for v1.21.4 is #9554.

[Claude Fable 5.1]

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. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants