Skip to content

Commit

Permalink
refactor wh server
Browse files Browse the repository at this point in the history
  • Loading branch information
m00g3n committed Jan 21, 2025
1 parent c14e44b commit 272d8ab
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions internal/webhook/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"sync"
"time"

"github.com/go-logr/logr"
"github.com/kyma-project/kim-snatch/internal/httpserver"
logf "github.com/kyma-project/kim-snatch/internal/log"
"github.com/kyma-project/kim-snatch/internal/metrics"
Expand Down Expand Up @@ -178,22 +177,27 @@ func (s *DefaultServer) Start(ctx context.Context) error {
}

if cfg.GetCertificate == nil {
go func(certPath, keyPath string, callback func(tls.Certificate), log logr.Logger, ctx context.Context) {
// Create the certificate watcher and
// set the config's GetCertificate on the TLSConfig
certWatcher, err := certwatcher.New(certPath, keyPath)
if err != nil {
log.Error(err, "failed to create cert watcher")
return
}
cfg.GetCertificate = certWatcher.GetCertificate
certWatcher.RegisterCallback(callback)
certPath := filepath.Join(s.Options.CertDir, s.Options.CertName)
keyPath := filepath.Join(s.Options.CertDir, s.Options.KeyName)

// Create the certificate watcher and
// set the config's GetCertificate on the TLSConfig
certWatcher, err := certwatcher.New(certPath, keyPath)
if err != nil {
return err
}

cfg.GetCertificate = certWatcher.GetCertificate
certWatcher.RegisterCallback(s.Options.Callback)

startWatcher := func() {
if err := certWatcher.Start(ctx); err != nil {
log.Error(err, "failed to start cert watcher")
return
}
}(filepath.Join(s.Options.CertDir, s.Options.CertName), filepath.Join(s.Options.CertDir, s.Options.KeyName), s.Options.Callback, log, ctx)
}

go startWatcher()
}

// Load CA to verify client certificate, if configured.
Expand Down

0 comments on commit 272d8ab

Please sign in to comment.