Skip to content

Commit d3c3ad6

Browse files
committed
Add timer to certpoolwatcher
Signed-off-by: Todd Short <[email protected]>
1 parent 2f22dcf commit d3c3ad6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/shared/util/http/certpoolwatcher.go

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type CertPoolWatcher struct {
2121
log logr.Logger
2222
watcher *fsnotify.Watcher
2323
done chan bool
24+
ticker *time.Ticker
2425
}
2526

2627
// Returns the current CertPool and the generation number
@@ -73,12 +74,15 @@ func NewCertPoolWatcher(caDir string, log logr.Logger) (*CertPoolWatcher, error)
7374
logPath(p, "watching certificate", log)
7475
}
7576

77+
ticker := time.NewTicker(10 * time.Minute)
78+
7679
cpw := &CertPoolWatcher{
7780
generation: 1,
7881
dir: caDir,
7982
pool: pool,
8083
log: log,
8184
watcher: watcher,
85+
ticker: ticker,
8286
done: make(chan bool),
8387
}
8488
go func() {
@@ -90,7 +94,10 @@ func NewCertPoolWatcher(caDir string, log logr.Logger) (*CertPoolWatcher, error)
9094
case err := <-watcher.Errors:
9195
log.Error(err, "error watching certificate dir")
9296
os.Exit(1)
97+
case <-ticker.C:
98+
cpw.update()
9399
case <-cpw.done:
100+
ticker.Stop()
94101
err := watcher.Close()
95102
if err != nil {
96103
log.Error(err, "error closing watcher")

internal/shared/util/http/certutil.go

+3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import (
1010
)
1111

1212
func NewCertPool(caDir string, log logr.Logger) (*x509.CertPool, error) {
13+
// Note that this already looks at SSL_CERT_DIR and SSL_CERT_FILE
14+
// So, we don't explicitly load certs from those locations
1315
caCertPool, err := x509.SystemCertPool()
1416
if err != nil {
1517
return nil, err
1618
}
19+
1720
if caDir == "" {
1821
return caCertPool, nil
1922
}

0 commit comments

Comments
 (0)