diff --git a/pkg/server/config_test.go b/pkg/server/config_test.go index acaab781c..0ce592c2a 100644 --- a/pkg/server/config_test.go +++ b/pkg/server/config_test.go @@ -88,7 +88,7 @@ func TestNewWithDelegate(t *testing.T) { stopCh := make(chan struct{}) defer close(stopCh) wrappingServer.PrepareRun() - wrappingServer.RunPostStartHooks() + wrappingServer.RunPostStartHooks(stopCh) server := httptest.NewServer(wrappingServer.Handler) defer server.Close() diff --git a/pkg/server/genericapiserver.go b/pkg/server/genericapiserver.go index a4fb9695f..a11148071 100644 --- a/pkg/server/genericapiserver.go +++ b/pkg/server/genericapiserver.go @@ -272,7 +272,7 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error { close(internalStopCh) }() - s.RunPostStartHooks() + s.RunPostStartHooks(stopCh) if _, err := systemd.SdNotify(true, "READY=1\n"); err != nil { glog.Errorf("Unable to send systemd daemon successful start message: %v\n", err) diff --git a/pkg/server/hooks.go b/pkg/server/hooks.go index 89ba6288a..1d6eb8cc8 100644 --- a/pkg/server/hooks.go +++ b/pkg/server/hooks.go @@ -43,6 +43,8 @@ type PostStartHookFunc func(context PostStartHookContext) error type PostStartHookContext struct { // LoopbackClientConfig is a config for a privileged loopback connection to the API server LoopbackClientConfig *restclient.Config + // StopCh is the channel that will be closed when the server stops + StopCh <-chan struct{} } // PostStartHookProvider is an interface in addition to provide a post start hook for the api server @@ -89,12 +91,15 @@ func (s *GenericAPIServer) AddPostStartHook(name string, hook PostStartHookFunc) } // RunPostStartHooks runs the PostStartHooks for the server -func (s *GenericAPIServer) RunPostStartHooks() { +func (s *GenericAPIServer) RunPostStartHooks(stopCh <-chan struct{}) { s.postStartHookLock.Lock() defer s.postStartHookLock.Unlock() s.postStartHooksCalled = true - context := PostStartHookContext{LoopbackClientConfig: s.LoopbackClientConfig} + context := PostStartHookContext{ + LoopbackClientConfig: s.LoopbackClientConfig, + StopCh: stopCh, + } for hookName, hookEntry := range s.postStartHooks { go runPostStartHook(hookName, hookEntry, context)