From 4134494fa51402ec5e5ea3fa1c51c0be55c955fd Mon Sep 17 00:00:00 2001 From: Abu Kashem Date: Fri, 6 Mar 2020 10:55:45 -0500 Subject: [PATCH] /readyz should start returning failure on shutdown initiation Currently, /readyz starts reporting failure after ShutdownDelayDuration elapses. We expect /readyz to start returning failure as soon as shutdown is initiated. This gives the load balancer a window defined by ShutdownDelayDuration to detect that /readyz is red and stop sending traffic to this server. --- .../src/k8s.io/apiserver/pkg/server/genericapiserver.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go index 07bad3d8c01..9c623f6485d 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go +++ b/staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go @@ -318,8 +318,14 @@ func (s preparedGenericAPIServer) Run(stopCh <-chan struct{}) error { go func() { defer close(delayedStopCh) + <-stopCh + // As soon as shutdown is initiated, /readyz should start returning failure. + // This gives the load balancer a window defined by ShutdownDelayDuration to detect that /readyz is red + // and stop sending traffic to this server. + close(s.readinessStopCh) + time.Sleep(s.ShutdownDelayDuration) }() @@ -379,7 +385,6 @@ func (s preparedGenericAPIServer) NonBlockingRun(stopCh <-chan struct{}) error { // ensure cleanup. go func() { <-stopCh - close(s.readinessStopCh) close(internalStopCh) if stoppedCh != nil { <-stoppedCh