Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
Fixes a crash-looping nil pointer dereference in the trigger controller’s renewal-window handling by adding a guard in CurrentCertificateNearingExpiry, and adds unit coverage for the affected paths.
Changes:
- Add a
renewalTime == nilguard inCurrentCertificateNearingExpiryto prevent dereferencing a nil renewal time whenpki.RenewalTimeerrors. - Add unit tests covering the renewal policy
Disabledpath and a renewal-window error path (invalid cron).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/controller/certificates/policies/checks.go | Adds a nil guard around renewalTime returned from pki.RenewalTime to prevent trigger-controller panics. |
| internal/controller/certificates/policies/checks_test.go | Adds tests for renewal-disabled behavior and renewal-window error handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Addressing review feedback on cert-manager#9109: the previous commit's nil guard in the trigger controller returned a WindowError violation whenever pki.RenewalTime handed back a nil time. Copilot pointed out this forces immediate re-issuance on any persistent window misconfiguration (e.g. windowDuration: 0s), even for a certificate nowhere near expiry, which would spam re-issuance while the config stays invalid. Fix it at the source instead. pki.RenewalTime now returns the deterministic renewBefore-based renewal time alongside the error for every non-Disabled path — the window-config errors and the unsupported policy default — exactly as the existing "cannot find a time" case already does. The trigger controller then gates renewal on that time and surfaces the WindowError reason only once renewal is actually due, and the readiness controller records a real Status.RenewalTime instead of nil while still flagging Ready=False. The nil dereference (cert-manager#9100) is now impossible by construction, so the guard is removed. Tests: renewaltime_test asserts the fallback time is returned for invalid cron, non-positive windowDuration, invalid timezone and unsupported policy; the trigger-controller test covers both the not-yet- due (no premature re-issuance) and due (WindowError surfaced) cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
|
@wallrj I agree with most changes here.. but when the config is invalid should we still populate the renewal time? |
|
@hjoshi123 You were right to push on that. On the ARI path we were populating a renewal time (a random time within the ARI suggested window) with no error surfaced at all when the renewal config was invalid. Fixed in c1f0871: the readiness controller now discards that value and recalculates deterministically, so on an invalid config We do still populate the fallback time in that case, deliberately: it keeps renewal scheduled on the sane default so the certificate cannot silently expire, while the condition and events make the misconfiguration visible. Leaving with claude fable-5 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Suppressed comments (1)
pkg/controller/certificates/readiness/readiness_controller.go:364
- Clearing only the local
renewalTimedoes not make the trigger controller use the deterministic fallback. The ARI suggested window was already stored above;gatherer.go:327-334forwards any such window, andCurrentCertificateNearingExpiryreturns from its ARI branch before callingRenewalTime. Consequently, an ARI-backed Certificate with invalid renewal windows still renews according to the ARI window and never reaches the newWindowError/default-schedule path. Clear the unusable suggested window here so the trigger evaluates the fallback schedule.
renewalTime = nil
|
@hjoshi123 This PR is ready for review. It fixes the controller crash loop in #9100 and has been waiting since 13 August. CI is green and the branch is up to date with You asked whether an invalid window config should still populate the renewal time. I addressed that in c1f0871: the readiness controller now discards the ARI time and surfaces [Claude Fable 5] |
|
/test pull-cert-manager-master-e2e-v1-37 |
c1f0871 to
1e19801
Compare
Addressing review feedback on cert-manager#9109: the previous commit's nil guard in the trigger controller returned a WindowError violation whenever pki.RenewalTime handed back a nil time. Copilot pointed out this forces immediate re-issuance on any persistent window misconfiguration (e.g. windowDuration: 0s), even for a certificate nowhere near expiry, which would spam re-issuance while the config stays invalid. Fix it at the source instead. pki.RenewalTime now returns the deterministic renewBefore-based renewal time alongside the error for every non-Disabled path — the window-config errors and the unsupported policy default — exactly as the existing "cannot find a time" case already does. The trigger controller then gates renewal on that time and surfaces the WindowError reason only once renewal is actually due, and the readiness controller records a real Status.RenewalTime instead of nil while still flagging Ready=False. The nil dereference (cert-manager#9100) is now impossible by construction, so the guard is removed. Tests: renewaltime_test asserts the fallback time is returned for invalid cron, non-positive windowDuration, invalid timezone and unsupported policy; the trigger-controller test covers both the not-yet- due (no premature re-issuance) and due (WindowError surfaced) cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
|
We repeated the real-cluster reproduction from #9100 against this branch. The branch fixes the problem in both the ways a cluster can meet it:
The upgrade test also uncovered a regression in the new validation, which we fixed in 7ded4c3: the Step 1: reproduce the crash on v1.21.1Kind cluster, cert-manager v1.21.1 from the Helm chart, plus the manifest from #9100 (self-signed ClusterIssuer and a Certificate with Transcript: admission accepts the manifest, controller crash-loops with the #9100 panic$ kubectl apply -f panic-repro.yaml
clusterissuer.cert-manager.io/selfsigned created
certificate.cert-manager.io/panic-repro created
$ kubectl -n cert-manager get pods -l app.kubernetes.io/component=controller
NAME READY STATUS RESTARTS AGE
cert-manager-d55696cd6-zr4br 0/1 CrashLoopBackOff 2 (10s ago) 67sStep 2: upgrade in place to this branchWe built images from this branch, loaded them into the same cluster, and upgraded the Helm release. The invalid Certificate was still in etcd. The controller stayed up and surfaced the error instead of crashing. Transcript: controller Running, Ready=False WindowError, fallback renewal time recorded$ kubectl -n cert-manager get pods -o custom-columns='NAME:.metadata.name,IMAGE:.spec.containers[0].image,RESTARTS:.status.containerStatuses[0].restartCount,STATUS:.status.phase'
NAME IMAGE RESTARTS STATUS
cert-manager-79bb645f4d-v496b cert-manager-controller-amd64:v1.21.0-beta.0-377-g7ded4c316617f1 0 Running
cert-manager-cainjector-77d8dbb4d9-d2bsv cert-manager-cainjector-amd64:v1.21.0-beta.0-377-g7ded4c316617f1 0 Running
cert-manager-webhook-5559d94b66-xzhpp cert-manager-webhook-amd64:v1.21.0-beta.0-377-g7ded4c316617f1 0 Running
$ kubectl get certificate panic-repro -o yaml
status:
conditions:
- lastTransitionTime: "2026-09-20T08:36:59Z"
message: 'Could not calculate renewal time: windowDuration must be a positive
duration in window { &Duration{Duration:0s,} * * * * *}'
observedGeneration: 1
reason: WindowError
status: "False"
type: Ready
notAfter: "2026-12-19T06:05:43Z"
notBefore: "2026-09-20T06:05:43Z"
renewalTime: "2026-11-19T06:05:43Z"
revision: 1
$ kubectl get events --field-selector involvedObject.name=panic-repro
LAST SEEN TYPE REASON OBJECT MESSAGE
3m3s Warning WindowError certificate/panic-repro Could not calculate renewal time: windowDuration must be a positive duration in window { &Duration{Duration:0s,} * * * * *}The Warning event repeats only when something triggers a reconcile, not continuously. Step 3: the webhook rejects the misconfiguration at submit timeCreating a fresh Certificate with Transcript: create denied, changed renewal denied, unrelated update allowed$ kubectl apply -f submit-repro.yaml
Error from server (Forbidden): error when creating "submit-repro.yaml": admission webhook "webhook.cert-manager.io" denied the request: spec.renewal.windows[0].windowDuration: Invalid value: "0s": windowDuration must be greater than 0
$ kubectl patch certificate panic-repro --type=merge -p '{"spec":{"renewal":{"policy":"RenewBefore","windows":[{"cron":"*/5 * * * *","windowDuration":"0s"}]}}}'
Error from server (Forbidden): admission webhook "webhook.cert-manager.io" denied the request: spec.renewal.windows[0].windowDuration: Invalid value: "0s": windowDuration must be greater than 0
$ kubectl annotate certificate panic-repro upgrade-test=annotate-while-invalid
certificate.cert-manager.io/panic-repro annotatedWhat the upgrade test caughtBefore 7ded4c3, the new rule fired on every update, so the webhook denied the readiness controller's own status updates for the pre-existing Certificate. The controller re-queued forever and Transcript: controller logs before the ratchet fix[Claude Fable 5] |
| // caller recalculate deterministically and surface the error as | ||
| // a WindowError Ready condition, the same as on reconciles that | ||
| // do not fetch ARI. | ||
| renewalTime = nil |
There was a problem hiding this comment.
@wallrj Setting the result to nil throws away a usable ARI-selected time and makes readiness fall back to renewBefore, while the trigger still uses the stored ARI window. That leaves the scheduled wake-up and renewal decision out of sync and undermines the renewal-time persistence.
I dont think its the scope of this PR to handle this case but I’d keep the time and propagate the window error separately so we can report WindowError without changing the schedule.
There was a problem hiding this comment.
You were right. Done in a3b90d9.
The readiness controller now keeps the ARI-selected time when the renewal configuration is invalid. status.renewalTime therefore stays in sync with the trigger controller, which schedules its recheck from that time and renews as soon as the suggested window opens.
One addition to your suggestion. The Ready condition is rebuilt from the policy chain on every reconcile, so an error carried only out of the ARI fetch would flap back to Ready=True on the reconciles in between. The controller now calculates the deterministic renewal time once per reconcile. That call revalidates the renewal configuration, so the WindowError condition is set on every reconcile, and its result is the fallback when there is no ARI-derived time.
TestProcessItemARIWindowErrorKeepsARITime covers the case you described: a reconcile that fetches ARI with an invalid window configuration must record the ARI-picked time, not the renewBefore fallback, alongside Ready=False WindowError.
[Claude Fable 5]
hjoshi123 pointed out that discarding the ARI-selected time on a window error desynchronises the scheduled wake-up from the renewal decision: the trigger controller renews as soon as the ARI suggested window opens, but status.renewalTime, which schedules the recheck, fell back to the renewBefore time. A revocation-driven window could then wait hours for an incidental reconcile. cert-manager#9109 (comment) Keep the ARI-derived time in status.renewalTime. To stop the window error being swallowed again, calculate the deterministic renewal time once on every reconcile: it revalidates the renewal configuration, so the WindowError Ready condition is set on every reconcile regardless of which time is used for the schedule, and it doubles as the fallback when no ARI time is available. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Signed-off-by: Artem Muterko <[email protected]>
pki.RenewalTime returns a nil time with an error for renewal-window errors (invalid cron, unknown timezone, non-positive windowDuration). The nil guard added here originally returned no violation, which would silently drop the error. Return it as a WindowError violation instead, matching how the function already reports window errors when the time is non-nil. This also fixes the nil pointer panic tracked in cert-manager#9100: a Certificate with windowDuration: 0s passes the admission webhook but is rejected at runtime, so the trigger controller crash-looped on the nil dereference. Added a regression test that panics without the guard. The Disabled policy path is unchanged: it is handled by the early return above, so a nil renewalTime here always means err != nil. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
Addressing review feedback on cert-manager#9109: the previous commit's nil guard in the trigger controller returned a WindowError violation whenever pki.RenewalTime handed back a nil time. Copilot pointed out this forces immediate re-issuance on any persistent window misconfiguration (e.g. windowDuration: 0s), even for a certificate nowhere near expiry, which would spam re-issuance while the config stays invalid. Fix it at the source instead. pki.RenewalTime now returns the deterministic renewBefore-based renewal time alongside the error for every non-Disabled path — the window-config errors and the unsupported policy default — exactly as the existing "cannot find a time" case already does. The trigger controller then gates renewal on that time and surfaces the WindowError reason only once renewal is actually due, and the readiness controller records a real Status.RenewalTime instead of nil while still flagging Ready=False. The nil dereference (cert-manager#9100) is now impossible by construction, so the guard is removed. Tests: renewaltime_test asserts the fallback time is returned for invalid cron, non-positive windowDuration, invalid timezone and unsupported policy; the trigger-controller test covers both the not-yet- due (no premature re-issuance) and due (WindowError surfaced) cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
The previous comment justified dereferencing renewalTime by reasoning
about a non-local invariant ("the only nil case is Disabled, handled by
the early return above"). That coupling is fragile: it panics if the
early return ever changes, which is exactly the crash-loop class this PR
fixes.
Handle nil for what it means instead: a nil renewal time is the Disabled
policy, so the certificate is never nearing expiry -- return no
violation. This is correct on its own, independent of the early return,
and cannot panic. The window-error comment now sits on the error branch
where it belongs.
No behaviour change: Disabled still yields no violation, window errors
still gate on the fallback time and surface WindowError when due.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
- Discard the random ARI-window fallback time when renewal-time calculation fails during an ARI fetch, so the readiness controller recalculates deterministically and sets the WindowError condition on every reconcile, instead of flapping between a random time with no condition and the deterministic fallback with one. - Fail loudly, not silently, if RenewalTime ever regresses to returning a nil time with an error: surface the WindowError violation rather than never renewing until the certificate expires. - Stop printing Status.RenewalTime (which may be nil or an unrelated ARI-derived time) in the trigger controller's WindowError message, and stop blaming renewal windows for errors that may not involve them. - Document the deliberate fail-open choice for unrecognised renewal policies, and state the non-nil-fallback contract on RenewalTime's godoc and the RenewalTimeFunc type. - Reject a zero or negative windowDuration at admission, matching the runtime check and the error message's own wording. - Update the readiness test fixture to the new contract: a window error now comes with a fallback time that must be recorded in Status.RenewalTime while Ready=False WindowError is set. - Build the window-error fallback once in applyRenewBeforeWithWindows so every return path shares it. - Pin NotBefore/NotAfter in the nearing-expiry window-error test instead of guessing the default validity, and fold the unsupported-policy fallback test into the sibling table test. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
A real-cluster upgrade test found that the new windowDuration validation blocked every update to Certificates that already carried windowDuration: 0s from a version without the rule, including the readiness controller's own status updates. The controller re-queued those Certificates forever and status.renewalTime was never recorded. Skip the rule on update when spec.renewal is unchanged, following the allowLegacyRenewBeforePercentageOnUpdate precedent in the same file. Create requests and updates that change spec.renewal are still rejected. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
hjoshi123 pointed out that discarding the ARI-selected time on a window error desynchronises the scheduled wake-up from the renewal decision: the trigger controller renews as soon as the ARI suggested window opens, but status.renewalTime, which schedules the recheck, fell back to the renewBefore time. A revocation-driven window could then wait hours for an incidental reconcile. cert-manager#9109 (comment) Keep the ARI-derived time in status.renewalTime. To stop the window error being swallowed again, calculate the deterministic renewal time once on every reconcile: it revalidates the renewal configuration, so the WindowError Ready condition is set on every reconcile regardless of which time is used for the schedule, and it doubles as the fallback when no ARI time is available. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
The embedlit modernize check added by cert-manager#9441 rejects the explicit metav1.ObjectMeta literal. Match the promoted-field form used throughout the file. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
27c07fb to
bdd99db
Compare
Three fixes from code review:
The WindowError override in the readiness controller now only replaces
a Ready=True condition. A violation found by the policy chain, such as
a mismatched Secret, is more actionable than the window error, which
stays visible through the Warning event. A new test scenario covers
the not-masked case.
The ARIError event for a renewal-configuration error is gone: the same
reconcile already emits a WindowError event for the same error, so an
ARI certificate with a bad window produced two near-identical warnings
per ARI fetch.
The windowDuration error no longer prints the window struct with %v,
which leaked Go syntax ({ &Duration{Duration:0s,} * * * * *}) into
Ready conditions and events. It now names the window by its cron.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
The readiness controller calculates the renewBefore-based renewal time on every reconcile to revalidate the renewal configuration. It applied any error from that calculation, even when the renewal time in use came from ARI. One of those errors is not about the configuration. "Cannot find a time with the given windows" depends on the desired renewal time. The same valid windows can have no occurrence after the renewBefore-based time and still have one after the ARI time. A Certificate on a valid ARI schedule was then marked Ready=False with WindowError. RenewalTime now wraps that error in pki.ErrNoRenewalWindow, with the message unchanged. The readiness controller ignores it when an ARI-derived time is in use. An invalid cron, timezone or windowDuration is still reported on every reconcile for any schedule. Also restore the ARIError event for a failed ARI-based calculation. Without it, an ARI window that misses every renewal window was reported nowhere when the renewBefore-based calculation succeeded. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
|
@hjoshi123 One more small change since your last review. Our 13 October change validated the renewal configuration on every reconcile. It also marked a Certificate on a valid ARI schedule as not ready when the renewBefore-based time had no renewal window after it. b66eedc fixes that: only an invalid configuration is reported for an ARI schedule. The ARI time is still kept, as you asked. The wider question of ARI windows that miss every renewal window is in #9639. [Claude Fable 5.2] |
|
/test pull-cert-manager-master-e2e-v1-37 |
|
PR needs rebase. 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. |
Addressing review feedback on cert-manager#9109: the previous commit's nil guard in the trigger controller returned a WindowError violation whenever pki.RenewalTime handed back a nil time. Copilot pointed out this forces immediate re-issuance on any persistent window misconfiguration (e.g. windowDuration: 0s), even for a certificate nowhere near expiry, which would spam re-issuance while the config stays invalid. Fix it at the source instead. pki.RenewalTime now returns the deterministic renewBefore-based renewal time alongside the error for every non-Disabled path — the window-config errors and the unsupported policy default — exactly as the existing "cannot find a time" case already does. The trigger controller then gates renewal on that time and surfaces the WindowError reason only once renewal is actually due, and the readiness controller records a real Status.RenewalTime instead of nil while still flagging Ready=False. The nil dereference (cert-manager#9100) is now impossible by construction, so the guard is removed. Tests: renewaltime_test asserts the fallback time is returned for invalid cron, non-positive windowDuration, invalid timezone and unsupported policy; the trigger-controller test covers both the not-yet- due (no premature re-issuance) and due (WindowError surfaced) cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
hjoshi123 pointed out that discarding the ARI-selected time on a window error desynchronises the scheduled wake-up from the renewal decision: the trigger controller renews as soon as the ARI suggested window opens, but status.renewalTime, which schedules the recheck, fell back to the renewBefore time. A revocation-driven window could then wait hours for an incidental reconcile. cert-manager#9109 (comment) Keep the ARI-derived time in status.renewalTime. To stop the window error being swallowed again, calculate the deterministic renewal time once on every reconcile: it revalidates the renewal configuration, so the WindowError Ready condition is set on every reconcile regardless of which time is used for the schedule, and it doubles as the fallback when no ARI time is available. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Richard Wall <[email protected]>
|
@wallrj Do you think we can rebase this PR? |
Pull Request Motivation
This fixes a nil pointer panic that crash-loops the cert-manager controller (#9100).
The panic happens when a Certificate uses
spec.renewal.windowswith a window that cannot be used: an invalid cron expression, an unknown timezone, or awindowDurationthat is not greater than 0.pki.RenewalTimereturned a nil time with the error.The trigger controller recorded the error and then dereferenced the nil time.
Closes #9100.
This supersedes #9067 by @archy-rock3t-cloud.
That PR was about 280 commits behind
masterand I could not push a rebase to it, because the fork belongs to an organisation.This PR carries the original commit, with authorship preserved, and adds follow-up commits.
What changes
pki.RenewalTimeDisabledpolicy.WindowErroras the reason once renewal is due.status.renewalTimeempty on a window errorReady=Falsewith reasonWindowErrorplus a Warning event.windowDuration: 0swindowDurationthat is not greater than 0.How a Certificate with an invalid window behaves
Ready=Falsewith reasonWindowErroron every reconcile, and a Warning event. A more specific problem found by the readiness checks, such as a mismatched Secret, is kept in the condition instead.How Certificates that use ARI behave
We agreed this with @hjoshi123 in this thread.
status.renewalTime. That keeps it in step with the trigger controller, which renews from the ARI suggested window.WindowErroron every reconcile.pki.RenewalTimenow returnspki.ErrNoRenewalWindowfor this case so that callers can tell it apart.What should happen when the ARI suggested window misses every renewal window is a separate question. It is tracked in #9639.
How the new webhook rule treats existing Certificates
The rule applies on create, and on update only when
spec.renewalchanges.This follows the
allowLegacyRenewBeforePercentageOnUpdateprecedent in the same file.windowDuration: 0sby an earlier version keeps working. Status and metadata updates are allowed.spec.renewalwithout fixing the value is rejected.How we tested it
pki.RenewalTime, the trigger controller before and after renewal is due, and the readiness controller with and without ARI.Kind
/kind bug
Release Note
[Claude Fable 5.2]