prevent unhandled errors on colliding poststarthook registration

Kubernetes-commit: 8d0c56e22f73fdb1a82a12475909e7d69f4bec08
This commit is contained in:
David Eads 2019-02-14 14:07:18 -05:00 committed by Kubernetes Publisher
parent af8f81df54
commit af92b436cc
3 changed files with 6 additions and 4 deletions

View File

@ -57,7 +57,7 @@ func TestNewWithDelegate(t *testing.T) {
})
delegatePostStartHookChan := make(chan struct{})
delegateServer.AddPostStartHook("delegate-post-start-hook", func(context PostStartHookContext) error {
delegateServer.AddPostStartHookOrDie("delegate-post-start-hook", func(context PostStartHookContext) error {
defer close(delegatePostStartHookChan)
return nil
})
@ -85,7 +85,7 @@ func TestNewWithDelegate(t *testing.T) {
})
wrappingPostStartHookChan := make(chan struct{})
wrappingServer.AddPostStartHook("wrapping-post-start-hook", func(context PostStartHookContext) error {
wrappingServer.AddPostStartHookOrDie("wrapping-post-start-hook", func(context PostStartHookContext) error {
defer close(wrappingPostStartHookChan)
return nil
})

View File

@ -92,7 +92,9 @@ func (s *GenericAPIServer) AddPostStartHook(name string, hook PostStartHookFunc)
// done is closed when the poststarthook is finished. This is used by the health check to be able to indicate
// that the poststarthook is finished
done := make(chan struct{})
s.AddHealthzChecks(postStartHookHealthz{name: "poststarthook/" + name, done: done})
if err := s.AddHealthzChecks(postStartHookHealthz{name: "poststarthook/" + name, done: done}); err != nil {
return err
}
s.postStartHooks[name] = postStartHookEntry{hook: hook, done: done}
return nil

View File

@ -496,7 +496,7 @@ func TestServerRunWithSNI(t *testing.T) {
// add poststart hook to know when the server is up.
startedCh := make(chan struct{})
s.AddPostStartHook("test-notifier", func(context PostStartHookContext) error {
s.AddPostStartHookOrDie("test-notifier", func(context PostStartHookContext) error {
close(startedCh)
return nil
})