Skip to content

Fix nil pointer panic on renewal-window errors in the trigger controller - #9109

Open
wallrj wants to merge 10 commits into
cert-manager:masterfrom
wallrj:pr-9067-wrapup
Open

wallrj wants to merge 10 commits into
cert-manager:masterfrom
wallrj:pr-9067-wrapup

Conversation

@wallrj

@wallrj wallrj commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

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.windows with a window that cannot be used: an invalid cron expression, an unknown timezone, or a windowDuration that is not greater than 0.
pki.RenewalTime returned 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 master and 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

Component Before After
pki.RenewalTime Returned a nil time with most errors Returns a usable time with every error. Nil now only means the Disabled policy.
Trigger controller Panicked on the nil time Renews at the renewBefore-based time and gives WindowError as the reason once renewal is due.
Readiness controller Left status.renewalTime empty on a window error Records a renewal time, and sets Ready=False with reason WindowError plus a Warning event.
Webhook Accepted windowDuration: 0s Rejects a windowDuration that is not greater than 0.

How a Certificate with an invalid window behaves

  • The controller no longer crashes.
  • The Certificate still renews, on the renewBefore-based schedule that it would have without windows. It cannot silently expire.
  • The Certificate is not re-issued early. The trigger controller waits until that time is reached.
  • The Certificate shows Ready=False with reason WindowError on 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.
  • The error message names the window by its cron expression.

How Certificates that use ARI behave

We agreed this with @hjoshi123 in this thread.

  • If the renewal configuration is invalid, the readiness controller keeps the ARI-selected time in status.renewalTime. That keeps it in step with the trigger controller, which renews from the ARI suggested window.
  • The invalid configuration is still reported as WindowError on every reconcile.
  • A valid configuration is not reported as an error only because the renewBefore-based time has no window after it. That error depends on the time being checked, and the ARI time is the one in use. pki.RenewalTime now returns pki.ErrNoRenewalWindow for 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.renewal changes.
This follows the allowLegacyRenewBeforePercentageOnUpdate precedent in the same file.

  • A Certificate stored with windowDuration: 0s by an earlier version keeps working. Status and metadata updates are allowed.
  • Changing spec.renewal without fixing the value is rejected.
  • Re-applying or restoring an old manifest that creates such a Certificate is rejected.

How we tested it

  • Unit tests cover each window error in pki.RenewalTime, the trigger controller before and after renewal is due, and the readiness controller with and without ARI.
  • We reproduced the crash on v1.21.1 in a Kind cluster and upgraded in place to this branch. The transcript is in this comment. That test ran before the ARI changes.

Kind

/kind bug

Release Note

Fix a nil pointer panic that could crash-loop the cert-manager controller when a Certificate used `spec.renewal.windows` with an invalid cron expression, an unknown timezone, or a `windowDuration` that was not greater than 0. Such a Certificate now renews on its `renewBefore` schedule and reports the problem as a `WindowError` Ready condition and a Warning event.
The webhook now rejects a `windowDuration` that is not greater than 0. Certificates stored before this change keep working, and the rule applies to them only when `spec.renewal` changes. Creating a Certificate with such a value is rejected, so re-applying or restoring an old manifest fails until the value is fixed.

[Claude Fable 5.2]

@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. labels Aug 8, 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 erikgb 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 Aug 8, 2026
@wallrj
wallrj requested review from hjoshi123 and a lite review from Copilot August 8, 2026 18:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == nil guard in CurrentCertificateNearingExpiry to prevent dereferencing a nil renewal time when pki.RenewalTime errors.
  • Add unit tests covering the renewal policy Disabled path 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.

wallrj added a commit to wallrj/cert-manager that referenced this pull request Aug 10, 2026
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]>
@cert-manager-prow cert-manager-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 10, 2026
@hjoshi123

Copy link
Copy Markdown
Collaborator

@wallrj I agree with most changes here.. but when the config is invalid should we still populate the renewal time?

@wallrj

wallrj commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

@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 status.renewalTime only ever holds the deterministic renewBefore-based fallback, and it is always accompanied by a Ready=False WindowError condition and a warning event.

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 status.renewalTime empty is what previously led to the nil-pointer panic in the trigger controller that this PR fixes.

with claude fable-5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 renewalTime does not make the trigger controller use the deterministic fallback. The ARI suggested window was already stored above; gatherer.go:327-334 forwards any such window, and CurrentCertificateNearingExpiry returns from its ARI branch before calling RenewalTime. Consequently, an ARI-backed Certificate with invalid renewal windows still renews according to the ARI window and never reaches the new WindowError/default-schedule path. Clear the unusable suggested window here so the trigger evaluates the fallback schedule.
				renewalTime = nil

@wallrj wallrj mentioned this pull request Sep 1, 2026
39 of 41 tasks
@wallrj

wallrj commented Sep 5, 2026 •

Copy link
Copy Markdown
Member Author

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

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 WindowError when the renewal config is invalid. Please let me know if that answers your question, or if you would prefer a different approach.

[Claude Fable 5]

@wallrj

wallrj commented Sep 5, 2026

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-37

@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 19, 2026
wallrj added a commit to wallrj/cert-manager that referenced this pull request Sep 20, 2026
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]>
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 20, 2026
@wallrj

wallrj commented Sep 20, 2026

Copy link
Copy Markdown
Member Author

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:

  1. The webhook now rejects windowDuration: 0s at submit time.
  2. A Certificate with windowDuration: 0s already in etcd, created by an earlier cert-manager version, no longer crashes the controller. The controller stays up, records the deterministic fallback in status.renewalTime, and reports the problem as a WindowError Ready condition and a Warning event.

The upgrade test also uncovered a regression in the new validation, which we fixed in 7ded4c3: the windowDuration > 0 rule initially rejected every update to a pre-existing invalid Certificate, including the readiness controller's own status updates. The controller re-queued those Certificates forever and could never record a renewal time. The rule is now enforced only when spec.renewal changes, following the allowLegacyRenewBeforePercentageOnUpdate precedent in the same file.

Step 1: reproduce the crash on v1.21.1

Kind cluster, cert-manager v1.21.1 from the Helm chart, plus the manifest from #9100 (self-signed ClusterIssuer and a Certificate with windowDuration: 0s). The webhook accepted the manifest and the controller entered CrashLoopBackOff within a minute.

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)   67s
panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x2814323]

goroutine 565 [running]:
...
github.com/cert-manager/cert-manager/pkg/controller/certificates/trigger.(*controllerWrapper).Register.NewTriggerPolicyChain.CurrentCertificateNearingExpiry.func1(...)
	internal/controller/certificates/policies/checks.go:316 +0x3c3
github.com/cert-manager/cert-manager/internal/controller/certificates/policies.Chain.Evaluate(...)
	internal/controller/certificates/policies/policies.go:61 +0x78
github.com/cert-manager/cert-manager/pkg/controller/certificates/trigger.(*controller).ProcessItem(...)

Step 2: upgrade in place to this branch

We 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. status.renewalTime holds the deterministic fallback: the certificate lives 90 days, so renewal is 30 days before expiry.

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 time

Creating a fresh Certificate with windowDuration: 0s is rejected. Updating the renewal configuration of the pre-existing Certificate without fixing it is also rejected. Updates that leave spec.renewal unchanged, such as the controller's status updates or a user adding an annotation, go through.

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 annotated

What the upgrade test caught

Before 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 status.renewalTime was never written. This would have affected every cluster upgrading with an invalid window already in etcd.

Transcript: controller logs before the ratchet fix
E0920 08:16:28.235830  1 controller.go:155] "re-queuing item due to error processing" err="admission webhook \"webhook.cert-manager.io\" denied the request: spec.renewal.windows[0].windowDuration: Invalid value: \"0s\": windowDuration must be greater than 0" logger="cert-manager.controller"
E0920 08:16:29.253210  1 controller.go:155] "re-queuing item due to error processing" err="admission webhook \"webhook.cert-manager.io\" denied the request: ..."
(repeats on every retry, capped at 30s intervals, indefinitely)

[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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

wallrj added a commit to wallrj/cert-manager that referenced this pull request Oct 11, 2026
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]>
@cert-manager-prow cert-manager-prow Bot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 11, 2026
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 3, 2026
@wallrj
wallrj requested a review from hjoshi123 November 3, 2026 16:29
@wallrj wallrj added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 3, 2026
@wallrj wallrj mentioned this pull request Nov 4, 2026
2 of 40 tasks
@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 Nov 21, 2026
archy-rock3t-cloud and others added 8 commits November 22, 2026 13:45
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]>
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2026
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]>
@wallrj

wallrj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

@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]

@wallrj

wallrj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

/test pull-cert-manager-master-e2e-v1-37

@cert-manager-prow

Copy link
Copy Markdown
Contributor

PR needs rebase.

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.

Abhaysiri pushed a commit to Abhaysiri/cert-manager that referenced this pull request Nov 26, 2026
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]>
Abhaysiri pushed a commit to Abhaysiri/cert-manager that referenced this pull request Nov 26, 2026
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]>
@hjoshi123

Copy link
Copy Markdown
Collaborator

@wallrj Do you think we can rebase this PR?

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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. 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.

Controller panic (nil pointer) at checks.go:316 when a renewal window errors, e.g. windowDuration: 0s

4 participants