From c2c7226ca45f2c9ebb2e66056b6b2694d6587eb1 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Wed, 19 Jun 2019 17:32:52 -0700 Subject: [PATCH] Obtain readyzLock once in installReadyz --- staging/src/k8s.io/apiserver/pkg/server/healthz.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/server/healthz.go b/staging/src/k8s.io/apiserver/pkg/server/healthz.go index 83e4ab6705c..cfe4efe8f03 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/healthz.go +++ b/staging/src/k8s.io/apiserver/pkg/server/healthz.go @@ -36,7 +36,12 @@ func (s *GenericAPIServer) AddHealthzChecks(checks ...healthz.HealthzChecker) er func (s *GenericAPIServer) AddReadyzChecks(checks ...healthz.HealthzChecker) error { s.readyzLock.Lock() defer s.readyzLock.Unlock() + return s.addReadyzChecks(checks...) +} +// addReadyzChecks allows you to add a HealthzCheck to readyz. +// premise: readyzLock has been obtained +func (s *GenericAPIServer) addReadyzChecks(checks ...healthz.HealthzChecker) error { if s.readyzChecksInstalled { return fmt.Errorf("unable to add because the readyz endpoint has already been created") } @@ -56,9 +61,9 @@ func (s *GenericAPIServer) installHealthz() { // installReadyz creates the readyz endpoint for this server. func (s *GenericAPIServer) installReadyz(stopCh <-chan struct{}) { - s.AddReadyzChecks(shutdownCheck{stopCh}) s.readyzLock.Lock() defer s.readyzLock.Unlock() + s.addReadyzChecks(shutdownCheck{stopCh}) s.readyzChecksInstalled = true @@ -99,7 +104,9 @@ func (s *GenericAPIServer) AddDelayedHealthzChecks(delay time.Duration, checks . s.healthzChecks = append(s.healthzChecks, delayedHealthCheck(check, s.healthzClock, s.maxStartupSequenceDuration)) } - return s.AddReadyzChecks(checks...) + s.readyzLock.Lock() + defer s.readyzLock.Unlock() + return s.addReadyzChecks(checks...) } // delayedHealthCheck wraps a health check which will not fail until the explicitly defined delay has elapsed.