Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/shared/util/http/certpoolwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type CertPoolWatcher struct {
log logr.Logger
watcher *fsnotify.Watcher
done chan bool
ticker *time.Ticker
}

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

ticker := time.NewTicker(10 * time.Minute)

cpw := &CertPoolWatcher{
generation: 1,
dir: caDir,
pool: pool,
log: log,
watcher: watcher,
ticker: ticker,
done: make(chan bool),
}
go func() {
Expand All @@ -90,7 +94,10 @@ func NewCertPoolWatcher(caDir string, log logr.Logger) (*CertPoolWatcher, error)
case err := <-watcher.Errors:
log.Error(err, "error watching certificate dir")
os.Exit(1)
case <-ticker.C:
cpw.update()
case <-cpw.done:
ticker.Stop()
err := watcher.Close()
if err != nil {
log.Error(err, "error closing watcher")
Expand Down
3 changes: 3 additions & 0 deletions internal/shared/util/http/certutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
)

func NewCertPool(caDir string, log logr.Logger) (*x509.CertPool, error) {
// Note that this already looks at SSL_CERT_DIR and SSL_CERT_FILE
// So, we don't explicitly load certs from those locations
caCertPool, err := x509.SystemCertPool()
if err != nil {
return nil, err
}

if caDir == "" {
return caCertPool, nil
}
Expand Down
Loading