Repository navigation
feat: Add configurable CertificateRequest max backoff duration as controller option - #8893
Conversation
|
Mostly looks good to me.. I had some minor quality of life changes that I wanted to do when I was changing the minimum stuff but I didnt do it as that was out of the scope of my PR. This would be a good time to do it acc to me |
70dd0ea to
c305403
Compare
|
Hi @hjoshi123, PR is ready for a re-review when you get a chance, thank you! |
|
This looks good to me @lunarwhite.. maybe we can wait for @wallrj since he reviewed the other PR too? |
There was a problem hiding this comment.
Pull request overview
Adds a new controller configuration option to cap the exponential retry backoff for failed CertificateRequests, replacing the previously hardcoded 32h ceiling and wiring the new setting through config API, CLI flags, Helm values, and controller context.
Changes:
- Introduce
certificateRequestMaximumBackoffDuration(default 32h) alongside the existing minimum backoff option (default 1h), including API/defaulting/conversion and Helm/CLI wiring. - Update trigger controller backoff calculation to compute exponential delay first and then cap to a configurable maximum (including overflow capping behavior).
- Extend unit/integration tests to account for the new maximum backoff option and validate capping behavior.
Reviewed changes
Copilot reviewed 16 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/integration/certificates/trigger_controller_test.go | Ensures integration test controller context sets the new max backoff duration. |
| test/integration/certificates/generates_new_private_key_per_request_test.go | Ensures integration test controller context sets the new max backoff duration. |
| pkg/controller/context.go | Adds max backoff duration to controller context options and updates inline docs. |
| pkg/controller/certificates/trigger/trigger_controller.go | Implements configurable max-backoff capping in trigger controller backoff logic. |
| pkg/controller/certificates/trigger/trigger_controller_test.go | Updates/extends unit tests for new max-backoff behavior and signature changes. |
| pkg/apis/config/controller/v1alpha1/zz_generated.deepcopy.go | Deepcopy support for the new config field. |
| pkg/apis/config/controller/v1alpha1/types.go | Adds the new config API field and associated docs. |
| internal/apis/config/controller/validation/validation.go | Adds cross-field validation for min/max backoff durations. |
| internal/apis/config/controller/validation/validation_test.go | Tests validation rules for min/max backoff durations. |
| internal/apis/config/controller/v1alpha1/zz_generated.conversion.go | Conversion support between v1alpha1 and internal config for the new field. |
| internal/apis/config/controller/v1alpha1/testdata/defaults.json | Updates defaulting golden file to include the new max backoff field. |
| internal/apis/config/controller/v1alpha1/defaults.go | Sets default max backoff duration (32h) when unset/zero. |
| internal/apis/config/controller/types.go | Adds the new field to internal controller configuration and updates docs. |
| deploy/charts/cert-manager/values.yaml | Documents Helm config keys for min/max backoff durations. |
| deploy/charts/cert-manager/values.schema.json | Updates schema description/example to include the new config keys. |
| deploy/charts/cert-manager/README.template.md | Documents Helm values for min/max backoff durations. |
| cmd/controller/app/options/options.go | Adds CLI flag for max backoff duration and updates flag help text. |
| cmd/controller/app/controller.go | Wires the new max backoff duration into the built controller context. |
Files not reviewed (2)
- internal/apis/config/controller/v1alpha1/zz_generated.conversion.go: Generated file
- pkg/apis/config/controller/v1alpha1/zz_generated.deepcopy.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wallrj-cyberark
left a comment
There was a problem hiding this comment.
I reviewed this alongside Copilot's automated pass. The two Copilot findings are genuine — see my replies on those threads. Here is the additional point Copilot did not flag, plus a scope summary.
Scope
The PR directly solves both linked issues. The motivating scenario (#8729) — a CA with a nightly maintenance window that causes the backoff to climb to 4–32 h, so cert-manager misses the recovery window entirely — is fixed by setting --certificate-request-maximum-backoff-duration=1h. The flag defaults to 32 h, preserving existing behaviour for users who do not set it.
The implementation follows the same structural pattern as #8312 (which added the minimum flag) and goes further: it adds cross-field validation (max >= min) and Helm chart entries that #8312 did not include.
Missing test: FailedIssuanceAttempts = 0
Copilot correctly flagged that n = 0 hits computed < initialDelay and sets delay = maxDelay rather than initialDelay. The existing tests only cover n >= 1. Although cert-manager itself never writes FailedIssuanceAttempts = 0 (the issuing controller initialises it to 1), a manual kubectl patch could produce this state. Adding one test case makes the intended behaviour explicit and guards against future regressions:
"with FailedIssuanceAttempts = 0 (manual patch edge case — should use initialDelay)": {
givenCert: gen.Certificate("cert-1", gen.SetCertificateNamespace("testns"),
gen.SetCertificateUID("cert-1-uid"),
gen.SetCertificateRevision(1),
gen.SetCertificateDNSNames("example.com"),
gen.SetCertificateLastFailureTime(metav1.NewTime(clock.Now())),
gen.SetCertificateIssuanceAttempts(new(0)),
),
givenNextCR: createCertificateRequestOrPanic(gen.Certificate("cert-1", gen.SetCertificateNamespace("testns"),
gen.SetCertificateUID("cert-1-uid"),
gen.SetCertificateRevision(1),
gen.SetCertificateDNSNames("example.com"),
)),
wantBackoff: true,
maxBackoffDuration: 32 * time.Hour,
wantDelay: 1 * time.Hour, // should clamp to initialDelay, not maxDelay
},Note: if the intended behaviour for n = 0 is actually maxDelay, the test should assert that instead — the key thing is to make it explicit.
Summary
Two items need addressing before merge (both confirmed via Copilot threads):
- Doc comments — the
(default 1h)parenthetical in the four minimum-backoff field descriptions reads as if the maximum defaults to 1 h; it should be reworded to clarify that 1 h is the default for the minimum field. FailedIssuanceAttempts = 0edge case — current code setsdelay = maxDelay; old code setdelay = initialDelay(via the safety guard). A test case and a comment documenting the chosen behaviour would be sufficient.
Apart from those two points the PR is in good shape. The logic is correct for all normal inputs, tests are thorough, and the Helm chart and integration tests are all updated.
Introduce `CertificateRequestMaximumBackoffDuration` field to the controller config API, `--certificate-request-maximum-backoff-duration` to the controller CLI flags, default as 32h for backwards compatibility. Allow users controlling the upper bound of exponential backoff after certificate request failures, which previously hardcoded at 32h. Signed-off-by: Yuedong Wu <[email protected]>
Replace hardcoded maxDelay/stopIncreaseBackoff constants with the configured `CertificateRequestMaximumBackoffDuration`, add overflow guard for extreme attempt counts. Signed-off-by: Yuedong Wu <[email protected]>
a8950e4 to
35e46aa
Compare
wallrj-cyberark
left a comment
There was a problem hiding this comment.
The latest revision addresses all review feedback. The maxBackoffDuration parameter is correctly wired end-to-end through the config API, flag registration, defaults, and controller context. The <= 0 guard for FailedIssuanceAttempts is a good defensive addition — it makes the edge case explicit rather than relying on the overflow-detection path. The validation rejecting negative values and max < min is a welcome addition. The test matrix now covers the main boundary conditions: below-cap, at-cap, constant (min == max), overflow, and the manual-patch edge case. Thank you for the thorough update.
- Add Major Themes section for the new --certificate-request-maximum-backoff-duration controller flag, with links to the CLI reference, ControllerConfiguration API, and FAQ retry section. - Add Feature changelog entry for cert-manager/cert-manager#8893. - Update FAQ to mention both backoff flags are now configurable. Signed-off-by: Richard Wall <[email protected]>
|
/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 |
|
@lunarwhite This change has been included in v1.21.0-beta.0, which is now published. If you are able to install the beta and verify that the |
Pull Request Motivation
Closes #8729
Closes #6201
Allow cluster admins to configure the maximum retry backoff duration for failed CertificateRequests, replacing the previously hardcoded cap of 32 hours. Cluster operators can now reduce the maximum wait time between retries from the default 32 hours to a shorter interval that fits their operational needs.
This mirrors the existing configuration option
certificateRequestMinimumBackoffDuration. (Prior art: #8312)Decisions being made
maxDelay. Replace the hardcodedfailedIssuanceAttempts > 6threshold. So cap works correctly for any configured initial delay. (e.g min=5m won't spike to 32h at attempt 6)initialDelay(which catches int64 wraparound to zero or negative) or exceedsmaxDelay, it is capped atmaxDelay.IsZero()to apply-defaults convention asCertificateRequestMinimumBackoffDurationand other sharedv1alpha1.Durationfields.E2E Verification
Deployed with these config flags should be ready and propagate to controller container arg
Cap enforcement at short interval (30s), backoff retries should plateau at 30s instead of climbing to hours
First create testing issuer and certificate
Check initial certificate state
Patch certificate status to simulate 3 consecutive failed issuance attempts that completed 5s ago. The backoff formula:
initialDelay * 2^(attempts-1) = 10s * 2^2 = 40s. But withmaxBackoff=30s, the cap should apply.Delete the TLS secret to trigger re-issuance during backoff window. The computed backoff is 30s (40s -> capped at 30s). With 5s elapsed, ~25s remaining.
From the trigger controller logs:
Proof 1: Certificate is
Ready=False(needs re-issuance), but no new certificaterequest was created. The trigger controller is respecting the backoff. Onlytest-cert-1(from the original issuance) exists.Wait for backoff expiry (capped at 30s)
Proof 2: After the capped 30s backoff expired,
test-cert-2was created and ready.failedIssuanceAttemptsreset to null,revisionincremented to 2.Simulate more failures for stress testing
Simulate 6 failures. Without the cap, the exponential formula produces
10s * 2^5 = 320s(>5 min). Withmax=30s, recovery should happen in ~30s.Proof 3: With 6 failed attempts, the exponential formula computes
10s × 2^5 = 320s(>5 minutes). But the certificate recovered in ~35s because themax=30scap is enforced.test-cert-3was created, succeeded, andfailedIssuanceAttemptsreset to null.Kind
/kind feature
Release Note