Skip to content

Commit

Permalink
fix issue when webhook server refreshing cert
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Dec 18, 2018
1 parent b497fd5 commit 5b51c4f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"k8s.io/apimachinery/pkg/runtime"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/inject"
Expand Down Expand Up @@ -219,11 +220,9 @@ func (s *Server) run(stop <-chan struct{}) error {
errCh <- srv.ListenAndServeTLS(path.Join(s.CertDir, writer.ServerCertName), path.Join(s.CertDir, writer.ServerKeyName))
}

timer := time.Tick(wait.Jitter(6*30*24*time.Hour, 0.1))
go serveFn()
for {
// TODO(mengqiy): add jitter to the timer
// Could use https://godoc.org/k8s.io/apimachinery/pkg/util/wait#Jitter
timer := time.Tick(6 * 30 * 24 * time.Hour)
select {
case <-timer:
changed, err := s.RefreshCert()
Expand All @@ -240,11 +239,16 @@ func (s *Server) run(stop <-chan struct{}) error {
log.Error(err, "encountering error when shutting down")
return err
}
timer = time.Tick(wait.Jitter(6*30*24*time.Hour, 0.1))
go serveFn()
case <-stop:
return nil
case e := <-errCh:
return e
// Don't exit when getting an http.ErrServerClosed error.
// We will get this error each time we restart the server.
if e != http.ErrServerClosed {
return e
}
}
}
}
Expand Down

0 comments on commit 5b51c4f

Please sign in to comment.