Repository navigation
fix(issuing): do not panic on a failed request with no Ready condition - #9118
cert-manager-prow[bot] merged 1 commit into
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. |
|
/ok-to-test |
There was a problem hiding this comment.
Pull request overview
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.
Fixes a panic in the certificates-issuing controller when handling CertificateRequests that have status.failureTime set but do not have a Ready condition.
Changes:
- Guard the “previous failed CertificateRequest” skip logic against a nil Ready condition to prevent nil dereference.
- Add a regression test case covering
failureTimeset with no Ready condition.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/controller/certificates/issuing/issuing_controller.go | Adds a nil check for crReadyCond before reading Reason, preventing controller panic. |
| pkg/controller/certificates/issuing/issuing_controller_test.go | Adds a regression test scenario for a CertificateRequest with failureTime but no Ready condition. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "if certificate is in Issuing state, one CertificateRequest with a failure time but no Ready condition, do nothing": { | ||
| certificate: exampleBundle.Certificate, | ||
| builder: &testpkg.Builder{ | ||
| CertManagerObjects: []runtime.Object{ | ||
| gen.CertificateFrom(issuingCert), | ||
| gen.CertificateRequestFrom(exampleBundle.CertificateRequest, | ||
| gen.AddCertificateRequestAnnotations(map[string]string{ | ||
| cmapi.CertificateRequestRevisionAnnotationKey: "2", // Current Certificate revision=1 | ||
| }), | ||
| gen.SetCertificateRequestFailureTime(metav1.Time{Time: metaFixedClockStart.Time.Add(time.Hour * -1)}), | ||
| )}, |
There was a problem hiding this comment.
Good catch, thank you. Fixed in 3779161.
The bundle helper in test/unit/crypto never sets Status.Conditions, so the case does exercise the nil path today, but only by accident of the fixture. It now clears them itself:
gen.CertificateRequestFrom(exampleBundle.CertificateRequest,
// Explicit, so the case keeps covering the missing condition.
func(cr *cmapi.CertificateRequest) { cr.Status.Conditions = nil },
...Re-checked both directions afterwards: the case passes with the fix, and reverting the crReadyCond != nil guard still panics with the nil dereference.
The previous-issuance guard reads crReadyCond.Reason, but crReadyCond is only checked for nil further down, after the Denied and InvalidRequest branches. A CertificateRequest that carries status.failureTime and has no Ready condition therefore dereferences a nil pointer and takes the controller down. The nil check is added to the guard rather than hoisted, because hoisting would change behaviour: a request that has been denied before an issuer set its Ready condition currently fails issuance, and moving the nil check above the Denied branch would make it wait instead. Signed-off-by: thc1006 <[email protected]>
3779161 to
a7927c3
Compare
|
/test pull-cert-manager-master-e2e-v1-36 |
wallrj
left a comment
There was a problem hiding this comment.
Thanks @thc1006!
The review confirmed the new test reproduces the panic from #9119 on the parent commit and passes with this fix, and I agree with your reasoning for failing (rather than waiting on) denied/invalid requests that have no Ready condition. Two non-blocking comments inline.
with claude fable-5
| // revision. Leave it to the certificate-requests controller to delete the | ||
| // CertificateRequest and create a new one. | ||
| if req.Status.FailureTime != nil && | ||
| if req.Status.FailureTime != nil && crReadyCond != nil && |
There was a problem hiding this comment.
Non-blocking: with this guard, a CertificateRequest which has status.failureTime but never gains a Ready condition falls through to the crReadyCond == nil wait branch below, and nothing ever unsticks it — the requestmanager controller skips deletion when the Ready condition is nil:
So the Certificate stays Issuing=True forever with only a debug-level log. The reorder suggested in #9119 has the same outcome, so this isn't a regression — and it takes an external status writer to hit, since the in-tree reporter sets failureTime and the Ready condition in the same status update — but the silent stall probably deserves an Event or an Info-level log. Happy for that to be a follow-up issue.
A related behaviour note: a stale request carrying Denied=True but no Ready condition now falls past this guard and fails the current issuance via CertificateRequestIsDenied. I think that's the right call — the wait path could never resolve it, for the same requestmanager reason above — just noting it's deliberate.
There was a problem hiding this comment.
Checked all three and they hold. requestmanager_controller.go:251 keeps a request whose Ready condition is nil in remaining rather than deleting it, and the branch this now falls into only logs at debug level, so the Certificate does sit at Issuing=True with nothing to move it along.
Worth saying plainly since you were kind about it: on main that path panics, so this change turns a crash into a silent stall. Better, but the silence is the part that should not stay.
Reporter.Failed sets FailureTime and the Ready condition in the same mutation, so the in-tree path cannot produce this state on its own, which matches what you said about an external status writer.
I will open the follow-up for the Event or Info-level log rather than grow this PR.
| gen.CertificateFrom(issuingCert), | ||
| gen.CertificateRequestFrom(exampleBundle.CertificateRequest, | ||
| // Explicit, so the case keeps covering the missing condition. | ||
| func(cr *cmapi.CertificateRequest) { cr.Status.Conditions = nil }, |
There was a problem hiding this comment.
nit: exampleBundle.CertificateRequest (built from test/unit/crypto's bare certificateRequest) never sets any status conditions, so this closure is a no-op today. The comment makes the defensive intent clear, so I'm happy either way — just noting it's the only inline-closure modifier in a file that otherwise sticks to gen.* modifiers.
There was a problem hiding this comment.
You are right that it does nothing today. test/unit/crypto never sets Status.Conditions on that request.
I would rather keep it, for the reason it is a closure at all: gen has SetCertificateRequestStatusCondition and AddCertificateRequestStatusCondition but nothing that clears them, and the fixture is shared with other suites. If a Ready condition is ever added there, this case would quietly stop covering the missing-condition path and still pass. Happy to drop it if you would rather the file stayed uniform.
|
/approve |
|
[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 |
|
/cherry-pick release-1.21 with claude fable-5 |
|
@wallrj: new pull request created: #9238 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. |
|
Verified on a single-node kubeadm cluster (Kubernetes v1.37.0) that had cert-manager v1.21.1 installed from the Helm chart, by reproducing the crash on v1.21.1 first and then upgrading with the bad object left in place. v1.21.1. A Certificate whose It kept crashing: restarts went 4 to 8 in about 100 seconds, v1.21.2. The Certificate stays at Thanks for including it. with claude opus-5 |
Pull Request Motivation
Fixes #9119
Spotted by @wallrj while reviewing #9116, and split out as he suggested since it is reachable on its own.
ProcessItemreadscrReadyCond.Reasonin the guard that skips a CertificateRequest which failed during a previous issuance:cert-manager/pkg/controller/certificates/issuing/issuing_controller.go
Lines 286 to 290 in 56d902b
but
crReadyCondis only checked for nil further down, after theDeniedandInvalidRequestbranches:cert-manager/pkg/controller/certificates/issuing/issuing_controller.go
Lines 322 to 325 in 56d902b
A CertificateRequest that carries
status.failureTimeand has no Ready condition therefore dereferences a nil pointer, and since this runs in the controller's process it takes the whole thing down rather than failing the one Certificate.I added the nil check to the guard instead of hoisting the existing one, because hoisting changes behaviour.
CertificateRequestIsDenieddoes not depend on the Ready condition, so a request denied before an issuer set Ready currently fails issuance; moving the nil check above that branch would make it wait instead. Adding the check where the dereference happens leaves every other path exactly as it was.Kind
/kind bug
Testing
TestIssuingControllergains a case withfailureTimeset and no Ready condition. On master it does not fail an assertion, it panics:Release Note
Documentation updates
NONE