🌱 expose cert refresh duration for testing via env. - #173
Conversation
Signed-off-by: Morven Cao <lcao@redhat.com>
WalkthroughIntroduces a test-configurable certificate reload interval by adding an exported variable Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: morvencao, qiujian16 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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/cloudevents/generic/options/cert/rotation.go (2)
30-37: Test-only duration override is documented clearly; consider clarifying exported usageThe comments clearly state the default (5m) and the test-only env override, which is good. Since
CertCallbackRefreshDurationis exported, callers can also override it programmatically in tests or specialized setups, independent of the env var. If that is intentional, you might mention it in the comment; if not, consider making the variable unexported and relying solely on the env-based hook.
39-54: StrengthenCERT_CALLBACK_REFRESH_DURATIONvalidation and align comment with behaviorThe
init()logic is generally solid: it only overrides on a set env var, usestime.ParseDuration, and logs/keeps the default on parse errors. Because this value is used as the interval forwait.PollUntilContextCancel, a zero or negative duration (whichParseDurationaccepts) could lead to extremely tight polling and unnecessary CPU usage if someone misconfigures the env var. (pkg.go.dev)Two concrete suggestions:
Validate for non-positive durations as well as parse errors
Treat
d <= 0as invalid and keep the default, logging a warning:func init() { // TEST-ONLY OVERRIDE: // Allow integration tests to reduce reload intervals by setting // CERT_CALLBACK_REFRESH_DURATION to a valid Go duration string (e.g., "10s"). // // If the variable is not set or is invalid, the default (5m) is preserved. if v := os.Getenv("CERT_CALLBACK_REFRESH_DURATION"); v != "" { d, err := time.ParseDuration(v) if err != nil { - // Optional: log or print a warning - klog.Warningf("invalid CERT_CALLBACK_REFRESH_DURATION (%q): %v, using default\n", v, err) - return - } - CertCallbackRefreshDuration = d + klog.Warningf("invalid CERT_CALLBACK_REFRESH_DURATION (%q): %v, using default", v, err) + return + } + if d <= 0 { + klog.Warningf("CERT_CALLBACK_REFRESH_DURATION must be > 0, got %q; using default", v) + return + } + CertCallbackRefreshDuration = d } }Remove the stale “Optional: log or print a warning” comment
Since you are already logging via
klog.Warningf, that comment is now misleading; the diff above drops it.These tweaks make the override safer under misconfiguration while keeping the test-only behavior you’re aiming for.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pkg/cloudevents/generic/options/cert/rotation.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: unit
- GitHub Check: integration
- GitHub Check: verify
🔇 Additional comments (1)
pkg/cloudevents/generic/options/cert/rotation.go (1)
3-12: Newosimport for env override is appropriate
osis only used to readCERT_CALLBACK_REFRESH_DURATIONininit(), which matches the new behavior; no issues here.
5f448fd
into
open-cluster-management-io:main
Summary
Related issue(s)
Fixes #
Summary by CodeRabbit
CERT_CALLBACK_REFRESH_DURATION(default: 5 minutes).✏️ Tip: You can customize this high-level summary in your review settings.