Skip to content

Commit bb47173

Browse files
author
Morven Cao
committed
expose cert refresh duration for testing via env.
Signed-off-by: Morven Cao <lcao@redhat.com>
1 parent 5e7a48e commit bb47173

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

pkg/cloudevents/generic/options/cert/rotation.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/tls"
77
"crypto/x509"
88
"fmt"
9+
"os"
910
"reflect"
1011
"sync"
1112
"time"
@@ -26,9 +27,32 @@ type Connection interface {
2627

2728
type reloadFunc func(*tls.CertificateRequestInfo) (*tls.Certificate, error)
2829

29-
// CertCallbackRefreshDuration is exposed so that integration tests can crank up the reload speed.
30+
// CertCallbackRefreshDuration controls how frequently certificate callbacks reload.
31+
// Default is 5 minutes.
32+
//
33+
// NOTE: This can be overridden via the environment variable
34+
//
35+
// CERT_CALLBACK_REFRESH_DURATION **for testing only**.
36+
// Do NOT rely on this environment variable in production.
3037
var CertCallbackRefreshDuration = 5 * time.Minute
3138

39+
func init() {
40+
// TEST-ONLY OVERRIDE:
41+
// Allow integration tests to reduce reload intervals by setting
42+
// CERT_CALLBACK_REFRESH_DURATION to a valid Go duration string (e.g., "10s").
43+
//
44+
// If the variable is not set or is invalid, the default (5m) is preserved.
45+
if v := os.Getenv("CERT_CALLBACK_REFRESH_DURATION"); v != "" {
46+
d, err := time.ParseDuration(v)
47+
if err != nil {
48+
// Optional: log or print a warning
49+
klog.Warningf("invalid CERT_CALLBACK_REFRESH_DURATION (%q): %v, using default\n", v, err)
50+
return
51+
}
52+
CertCallbackRefreshDuration = d
53+
}
54+
}
55+
3256
type clientCertRotating struct {
3357
sync.RWMutex
3458

0 commit comments

Comments
 (0)