Repository navigation
Record a Warning event when CSR generation fails - #9140
cert-manager-prow[bot] merged 2 commits into
Conversation
createNewCertificateRequest already handles the CertificateRequest-creation failure case by recording a Warning event via the reasonRequestFailed reason, but the earlier CSR-generation failure (pki.GenerateCSR) a few lines above it only logs the error and returns nil, so it's silently swallowed. A Certificate that hits this path gets stuck at Issuing=True/Ready=False indefinitely, since no CertificateRequest is ever created to clear the condition, with no Event or condition change to signal anything is wrong - the only trace is a controller log line. This mirrors the existing pattern for the sibling failure case a few lines below, so the fix is independent of what causes GenerateCSR to fail (e.g. a malformed nameConstraints IP range, added as the regression test here). Signed-off-by: yogeshbendre <[email protected]>
|
Hi @yogeshbendre. 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. |
There was a problem hiding this comment.
Pull request overview
Records a user-visible Warning event when CSR generation fails during certificate issuance or renewal.
Changes:
- Emits a
RequestFailedWarning event for CSR generation errors. - Adds regression coverage using malformed NameConstraints.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
requestmanager_controller.go |
Records CSR generation failures as events. |
requestmanager_controller_test.go |
Verifies the Warning event is emitted. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wallrj
left a comment
There was a problem hiding this comment.
Thanks @yogeshbendre — this is a useful improvement; until now this failure was only visible in the controller logs. One suggestion inline, plus two non-blocking observations:
-
The root cause is one level deeper: admission validation of
nameConstraintschecks the feature gate,isCAand permitted/excluded presence, but never parsesipRanges(certificate.go#L215-L227), so this permanently un-issuable spec is accepted at apply time. The event is still worth having — it also covers otherGenerateCSRfailure modes such as literal subject parse errors — but a follow-up validating the CIDRs at admission would reject the bad spec atkubectl apply. Happy to open an issue for that. -
The sibling failure paths just below (
pki.EncodeCSR,pem.Encode) still return the error and retry forever with backoff and no event — the same invisibility problem, but pre-existing and rare; nothing to do in this PR.
with claude fable-5
| ) | ||
| if err != nil { | ||
| log.Error(err, "Failed to generate CSR - will not retry") | ||
| c.recorder.Eventf(crt, corev1.EventTypeWarning, reasonRequestFailed, "Failed to generate CSR: %s", err.Error()) |
There was a problem hiding this comment.
Consider matching the log line by saying "will not retry" in the event too:
| c.recorder.Eventf(crt, corev1.EventTypeWarning, reasonRequestFailed, "Failed to generate CSR: %s", err.Error()) | |
| c.recorder.Eventf(crt, corev1.EventTypeWarning, reasonRequestFailed, "Failed to generate CSR: %s - will not retry", err.Error()) |
The claim is accurate: return nil here routes the item to queue.Forget, so it is never requeued with backoff. The next attempt is a spec change or the 10 hour informer resync, and since the error is derived purely from the spec, every re-attempt fails identically. Without this, someone watching kubectl describe may wait for cert-manager to recover on its own when it never will.
(The expected event string in the new test case will need the matching update.)
There was a problem hiding this comment.
Thank you @wallrj , this is a very good feedback.
I have made the necessary changes and retested.
Pushed the changes to the repo.
The logs now look as follows:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Issuing 17s cert-manager-certificates-trigger Issuing certificate as Secret does not exist
Normal Generated 17s cert-manager-certificates-key-manager Stored new private key in temporary Secret resource "repro-root-ca-brzn6"
Warning RequestFailed 17s cert-manager-certificates-request-manager Failed to generate CSR: invalid CIDR address: 10.0.0.0 - will not retry
Signed-off-by: yogeshbendre <[email protected]>
|
/ok-to-test |
|
Thanks @yogeshbendre, the event message and test now match the log line. /approve with 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 |
|
Thank you @wallrj for your useful reviews and approvals. :) Also thanks for the two new related issues, they make perfect sense. |
Pull Request Motivation
Fixes #9139
This is to fix the issue #9139.
createNewCertificateRequest(pkg/controller/certificates/requestmanager/requestmanager_controller.go)already records a Warning event via the
reasonRequestFailedreason when creating theCertificateRequestobject fails, but when the earlier
pki.GenerateCSRcall fails, the error is only logged(
"Failed to generate CSR - will not retry") and the function returnsnil— silently swallowed. Sincenothing else clears the
Certificate'sIssuingcondition without aCertificateRequestbeing created, thisleaves the
Certificatestuck atReady=Falseindefinitely with zero user-visible signal beyond a controllerlog line.
This PR adds the same
c.recorder.Eventf(...)call already used for the sibling failure path a few linesbelow, so both failure modes in this function are now surfaced consistently. It's a one-line functional
change plus a regression test (added to the existing table-driven
TestProcessItemsuite) that reproducesthe swallow via a malformed
nameConstraintsIP range — confirmed the added test fails without the fix andpasses with it.
Reproduced live on a
kindcluster running cert-manager v1.21.1 before filing (details in the linked issue),then verified the fix itself end-to-end: built this branch into a real controller image, swapped it into the
same live cluster in place of the stock image, and confirmed
kubectl describe certificatenow showsWarning RequestFailed Failed to generate CSR: ...on the same Certificate that previously showed no eventsat all.
Before Fix
There is no recoreded warning event from
kubectl describe certificateAfter Fix
Note generated warning event from
kubectl describe certificateKind
/kind bug
Release Note