Skip to content

feat: Add configurable CertificateRequest max backoff duration as controller option - #8893

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
lunarwhite:max-backoff-duration
Jun 30, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
lunarwhite:max-backoff-duration

Conversation

@lunarwhite

@lunarwhite lunarwhite commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

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

  • Compute the delay first, then cap if it exceeds maxDelay. Replace the hardcoded failedIssuanceAttempts > 6 threshold. So cap works correctly for any configured initial delay. (e.g min=5m won't spike to 32h at attempt 6)
  • Overflow is detected after computation: if the result is less than initialDelay (which catches int64 wraparound to zero or negative) or exceeds maxDelay, it is capped at maxDelay.
  • max=0 treated as "use default" rather than "unlimited". Follow the same IsZero() to apply-defaults convention as CertificateRequestMinimumBackoffDuration and other shared v1alpha1.Duration fields.
  • max>=min enforced as cross-field check. Allow min==max (constant backoff), reject negative values for either field.

E2E Verification

Deployed with these config flags should be ready and propagate to controller container arg
$ helm upgrade --install \
    --namespace cert-manager \
    --create-namespace \
    --set "extraArgs={--certificate-request-maximum-backoff-duration=30s,--certificate-request-minimum-backoff-duration=10s}" \
    cert-manager $(E2E_CERT_MANAGER_CHART)

$ kubectl get pods -n cert-manager
NAME                                      READY   STATUS    RESTARTS   AGE
cert-manager-747bffbf4-zrxst              1/1     Running   0          20s
cert-manager-cainjector-cb7f69858-qldk2   1/1     Running   0          20s
cert-manager-webhook-648c79bddf-bb8tq     1/1     Running   0          20s

$ kubectl get deployment -n cert-manager cert-manager -o json | jq '.spec.template.spec.containers[0].args'
[
  ...
  "--certificate-request-maximum-backoff-duration=30s",
  "--certificate-request-minimum-backoff-duration=10s",
  ...
]
Cap enforcement at short interval (30s), backoff retries should plateau at 30s instead of climbing to hours

First create testing issuer and certificate

$ kubectl apply -f - <<'EOF'
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: selfsigned-issuer
spec:
  selfSigned: {}
EOF
issuer.cert-manager.io/selfsigned-issuer created

$ kubectl wait --for=condition=Ready issuer selfsigned-issuer --timeout=30s
issuer.cert-manager.io/selfsigned-issuer condition met

$ kubectl apply -f - <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: test-cert
spec:
  secretName: test-cert-tls
  commonName: example.com
  issuerRef:
    name: selfsigned-issuer
    kind: Issuer
EOF
certificate.cert-manager.io/test-cert created

$ kubectl wait --for=condition=Ready certificate test-cert --timeout=60s
certificate.cert-manager.io/test-cert condition met

Check initial certificate state

$ kubectl get certificate test-cert -o json | jq '{
  ready: .status.conditions[] | select(.type=="Ready") | .status,
  failedIssuanceAttempts: .status.failedIssuanceAttempts,
  lastFailureTime: .status.lastFailureTime,
  revision: .status.revision
}'
{
  "ready": "True",
  "failedIssuanceAttempts": null,
  "lastFailureTime": null,
  "revision": 1
}

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 with maxBackoff=30s, the cap should apply.

$ FAIL_TIME=$(date -u -v-5S +"%Y-%m-%dT%H:%M:%SZ")
$ kubectl patch certificate test-cert --type=merge --subresource=status -p '{
  "status": {
    "lastFailureTime": "'$FAIL_TIME'",
    "failedIssuanceAttempts": 3
  }
}'
certificate.cert-manager.io/test-cert patched

$ kubectl get certificate test-cert -o json | jq '{
  ready: .status.conditions[] | select(.type=="Ready") | .status,
  failedIssuanceAttempts: .status.failedIssuanceAttempts,
  lastFailureTime: .status.lastFailureTime
}'
{
  "ready": "True",
  "failedIssuanceAttempts": 3,
  "lastFailureTime": "2026-06-18T12:08:09Z"
}

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.

$ kubectl delete secret test-cert-tls
secret "test-cert-tls" deleted

$ kubectl get certificate test-cert -o json | jq '{
  ready: .status.conditions[] | select(.type=="Ready") | .status,
  failedIssuanceAttempts: .status.failedIssuanceAttempts,
  lastFailureTime: .status.lastFailureTime,
  revision: .status.revision
}'
{
  "ready": "False",
  "failedIssuanceAttempts": 3,
  "lastFailureTime": "2026-06-18T12:08:09Z",
  "revision": 1
}

$ kubectl get certificaterequests
NAME          APPROVED   DENIED   READY   ISSUER              REQUESTER                                         AGE
test-cert-1   True                True    selfsigned-issuer   system:serviceaccount:cert-manager:cert-manager   51s

From the trigger controller logs:

I0618 12:08:14.339515 trigger_controller.go:238] "Certificate must be re-issued" 
  logger="cert-manager.controller" key="e2e-test/test-cert" reason="DoesNotExist" 
  message="Issuing certificate as Secret does not exist"

Proof 1: Certificate is Ready=False (needs re-issuance), but no new certificaterequest was created. The trigger controller is respecting the backoff. Only test-cert-1 (from the original issuance) exists.

Wait for backoff expiry (capped at 30s)

$ sleep 30
$ kubectl get certificate test-cert -o json | jq '{
  ready: .status.conditions[] | select(.type=="Ready") | .status,
  failedIssuanceAttempts: .status.failedIssuanceAttempts,
  lastFailureTime: .status.lastFailureTime,
  revision: .status.revision
}'
{
  "ready": "True",
  "failedIssuanceAttempts": null,
  "lastFailureTime": null,
  "revision": 2
}

$ kubectl get certificaterequests
NAME          APPROVED   DENIED   READY   ISSUER              REQUESTER                                         AGE
test-cert-2   True                True    selfsigned-issuer   system:serviceaccount:cert-manager:cert-manager   17s

Proof 2: After the capped 30s backoff expired, test-cert-2 was created and ready. failedIssuanceAttempts reset to null, revision incremented to 2.

Simulate more failures for stress testing

Simulate 6 failures. Without the cap, the exponential formula produces 10s * 2^5 = 320s (>5 min). With max=30s, recovery should happen in ~30s.

$ FAIL_TIME=$(date -u -v-2S +"%Y-%m-%dT%H:%M:%SZ")
$ kubectl patch certificate test-cert --type=merge --subresource=status -p '{
  "status": {
    "lastFailureTime": "'$FAIL_TIME'",
    "failedIssuanceAttempts": 6
  }
}'
certificate.cert-manager.io/test-cert patched

$ kubectl delete secret test-cert-tls
secret "test-cert-tls" deleted

$ sleep 5
$ kubectl get certificaterequests
NAME          APPROVED   DENIED   READY   ISSUER              REQUESTER                                         AGE
test-cert-2   True                True    selfsigned-issuer   system:serviceaccount:cert-manager:cert-manager   35s

# no new CR yet, backoff active

$ sleep 30
$ kubectl get certificate test-cert -o json | jq '{
  ready: .status.conditions[] | select(.type=="Ready") | .status,
  failedIssuanceAttempts: .status.failedIssuanceAttempts,
  revision: .status.revision
}'
{
  "ready": "True",
  "failedIssuanceAttempts": null,
  "revision": 3
}

$ kubectl get certificaterequests
NAME          APPROVED   DENIED   READY   ISSUER              REQUESTER                                         AGE
test-cert-3   True                True    selfsigned-issuer   system:serviceaccount:cert-manager:cert-manager   7s

Proof 3: With 6 failed attempts, the exponential formula computes 10s × 2^5 = 320s (>5 minutes). But the certificate recovered in ~35s because the max=30s cap is enforced. test-cert-3 was created, succeeded, and failedIssuanceAttempts reset to null.

Kind

/kind feature

Release Note

Add `certificateRequestMaximumBackoffDuration` controller configuration option to cap retry backoff time for failed CertificateRequests. Configurable via config file, `--certificate-request-maximum-backoff-duration` CLI flag, or Helm value `config.certificateRequestMaximumBackoffDuration`. Defaults to 32 hours for backward compatibility.

@cert-manager-prow cert-manager-prow Bot added kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. area/api Indicates a PR directly modifies the 'pkg/apis' directory area/deploy Indicates a PR modifies deployment configuration area/testing Issues relating to testing size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 18, 2026
@hjoshi123

Copy link
Copy Markdown
Collaborator

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

@lunarwhite
lunarwhite force-pushed the max-backoff-duration branch 2 times, most recently from 70dd0ea to c305403 Compare June 22, 2026 11:30
@lunarwhite
lunarwhite requested a review from hjoshi123 June 22, 2026 11:58
@lunarwhite

Copy link
Copy Markdown
Member Author

Hi @hjoshi123, PR is ready for a re-review when you get a chance, thank you!

@hjoshi123

Copy link
Copy Markdown
Collaborator

This looks good to me @lunarwhite.. maybe we can wait for @wallrj since he reviewed the other PR too?
This is on my list and we will get it merged before the 1.21 release. Thank you for taking this up again :)

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

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.

Comment thread pkg/controller/context.go Resolved
Comment thread cmd/controller/app/options/options.go Resolved

@wallrj-cyberark wallrj-cyberark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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):

  1. 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.
  2. FailedIssuanceAttempts = 0 edge case — current code sets delay = maxDelay; old code set delay = 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.

@wallrj-cyberark
wallrj-cyberark requested a review from wallrj June 30, 2026 16:22
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]>
@lunarwhite
lunarwhite force-pushed the max-backoff-duration branch from a8950e4 to 35e46aa Compare June 30, 2026 17:02

@wallrj-cyberark wallrj-cyberark left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

wallrj-cyberark added a commit to wallrj-cyberark/cert-manager-website that referenced this pull request Jun 30, 2026
- 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]>
@wallrj

wallrj commented Jun 30, 2026

Copy link
Copy Markdown
Member

/approve
/lgtm

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Jun 30, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[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

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 30, 2026
@wallrj-cyberark
wallrj-cyberark dismissed hjoshi123’s stale review June 30, 2026 18:38

I THINK it was addressed.

@cert-manager-prow
cert-manager-prow Bot merged commit ae67234 into cert-manager:master Jun 30, 2026
@lunarwhite
lunarwhite deleted the max-backoff-duration branch July 1, 2026 00:38
@wallrj-cyberark

Copy link
Copy Markdown
Member

@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 --certificate-request-maximum-backoff-duration flag works as expected in your environment, that would be much appreciated. Thank you for the contribution.