diff --git a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go index c665e418830..5f4e8e348a8 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go +++ b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go @@ -338,6 +338,7 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error { go func() { defer delayedStopCh.Signal() + defer klog.V(1).InfoS("[graceful-termination] shutdown event", "name", delayedStopCh.Name()) <-stopCh @@ -345,6 +346,7 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error { // This gives the load balancer a window defined by ShutdownDelayDuration to detect that /readyz is red // and stop sending traffic to this server. shutdownInitiatedCh.Signal() + klog.V(1).InfoS("[graceful-termination] shutdown event", "name", shutdownInitiatedCh.Name()) time.Sleep(s.ShutdownDelayDuration) }() @@ -358,11 +360,13 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error { go func() { <-listenerStoppedCh httpServerStoppedListeningCh.Signal() + klog.V(1).InfoS("[graceful-termination] shutdown event", "name", httpServerStoppedListeningCh.Name()) }() drainedCh := s.lifecycleSignals.InFlightRequestsDrained go func() { defer drainedCh.Signal() + defer klog.V(1).InfoS("[graceful-termination] shutdown event", "name", drainedCh.Name()) // wait for the delayed stopCh before closing the handler chain (it rejects everything after Wait has been called). <-delayedStopCh.Signaled() diff --git a/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go b/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go index a4e44e986fe..2297a776ed4 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go +++ b/staging/src/k8s.io/apiserver/pkg/server/lifecycle_signals.go @@ -16,10 +16,6 @@ limitations under the License. package server -import ( - "k8s.io/klog/v2" -) - /* We make an attempt here to identify the events that take place during lifecycle of the apiserver. @@ -69,6 +65,9 @@ type lifecycleSignal interface { // Signaled returns a channel that is closed when the underlying event // has been signaled. Successive calls to Signaled return the same value. Signaled() <-chan struct{} + + // Name returns the name of the signal, useful for logging. + Name() string } // lifecycleSignals provides an abstraction of the events that @@ -127,10 +126,13 @@ func (e *namedChannelWrapper) Signal() { // already closed, don't close again. default: close(e.ch) - klog.V(1).InfoS("[graceful-termination] shutdown event", "name", e.name) } } func (e *namedChannelWrapper) Signaled() <-chan struct{} { return e.ch } + +func (e *namedChannelWrapper) Name() string { + return e.name +}