Merge pull request #99064 from serathius/checks

Allow adding healthz and livez checks independent to each other
This commit is contained in:
Kubernetes Prow Robot 2021-02-16 13:45:35 -08:00 committed by GitHub
commit 67d407180b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -633,7 +633,7 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
} }
} }
// TODO: Once we get rid of /healthz consider changing this to post-start-hook. // TODO: Once we get rid of /healthz consider changing this to post-start-hook.
err := s.addReadyzChecks(healthz.NewInformerSyncHealthz(c.SharedInformerFactory)) err := s.AddReadyzChecks(healthz.NewInformerSyncHealthz(c.SharedInformerFactory))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -53,11 +53,14 @@ func (s *GenericAPIServer) addHealthChecks(livezGracePeriod time.Duration, check
return fmt.Errorf("unable to add because the healthz endpoint has already been created") return fmt.Errorf("unable to add because the healthz endpoint has already been created")
} }
s.healthzChecks = append(s.healthzChecks, checks...) s.healthzChecks = append(s.healthzChecks, checks...)
return s.addLivezChecks(livezGracePeriod, checks...) if err := s.AddLivezChecks(livezGracePeriod, checks...); err != nil {
return err
}
return s.AddReadyzChecks(checks...)
} }
// addReadyzChecks allows you to add a HealthCheck to readyz. // AddReadyzChecks allows you to add a HealthCheck to readyz.
func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthChecker) error { func (s *GenericAPIServer) AddReadyzChecks(checks ...healthz.HealthChecker) error {
s.readyzLock.Lock() s.readyzLock.Lock()
defer s.readyzLock.Unlock() defer s.readyzLock.Unlock()
if s.readyzChecksInstalled { if s.readyzChecksInstalled {
@ -67,9 +70,8 @@ func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthChecker) erro
return nil return nil
} }
// addLivezChecks allows you to add a HealthCheck to livez. It will also automatically add a check to readyz, // AddLivezChecks allows you to add a HealthCheck to livez.
// since we want to avoid being ready when we are not live. func (s *GenericAPIServer) AddLivezChecks(delay time.Duration, checks ...healthz.HealthChecker) error {
func (s *GenericAPIServer) addLivezChecks(delay time.Duration, checks ...healthz.HealthChecker) error {
s.livezLock.Lock() s.livezLock.Lock()
defer s.livezLock.Unlock() defer s.livezLock.Unlock()
if s.livezChecksInstalled { if s.livezChecksInstalled {
@ -78,14 +80,14 @@ func (s *GenericAPIServer) addLivezChecks(delay time.Duration, checks ...healthz
for _, check := range checks { for _, check := range checks {
s.livezChecks = append(s.livezChecks, delayedHealthCheck(check, s.livezClock, delay)) s.livezChecks = append(s.livezChecks, delayedHealthCheck(check, s.livezClock, delay))
} }
return s.addReadyzChecks(checks...) return nil
} }
// addReadyzShutdownCheck is a convenience function for adding a readyz shutdown check, so // addReadyzShutdownCheck is a convenience function for adding a readyz shutdown check, so
// that we can register that the api-server is no longer ready while we attempt to gracefully // that we can register that the api-server is no longer ready while we attempt to gracefully
// shutdown. // shutdown.
func (s *GenericAPIServer) addReadyzShutdownCheck(stopCh <-chan struct{}) error { func (s *GenericAPIServer) addReadyzShutdownCheck(stopCh <-chan struct{}) error {
return s.addReadyzChecks(shutdownCheck{stopCh}) return s.AddReadyzChecks(shutdownCheck{stopCh})
} }
// installHealthz creates the healthz endpoint for this server // installHealthz creates the healthz endpoint for this server