Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Obtain readyzLock once in installReadyz to prevent double addition of readyz check #79112

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/server/healthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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

Expand Down Expand Up @@ -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...)
tedyu marked this conversation as resolved.
Show resolved Hide resolved
}

// delayedHealthCheck wraps a health check which will not fail until the explicitly defined delay has elapsed.
Expand Down