From 5489f68e2fa174329a80d62b83415f13f04ab35a Mon Sep 17 00:00:00 2001 From: Monis Khan Date: Sat, 28 Aug 2021 11:23:11 -0400 Subject: [PATCH] supervisor: ensure graceful exit The kubelet will send the SIGTERM signal when it wants a process to exit. After a grace period, it will send the SIGKILL signal to force the process to terminate. The concierge has always handled both SIGINT and SIGTERM as indicators for it to gracefully exit (i.e. stop watches, controllers, etc). This change updates the supervisor to do the same (previously it only handled SIGINT). This is required to allow the leader election lock release logic to run. Otherwise it can take a few minutes for new pods to acquire the lease since they believe it is already held. Signed-off-by: Monis Khan --- internal/supervisor/server/server.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/supervisor/server/server.go b/internal/supervisor/server/server.go index 92861747..329dfb83 100644 --- a/internal/supervisor/server/server.go +++ b/internal/supervisor/server/server.go @@ -14,6 +14,7 @@ import ( "os" "os/signal" "strings" + "syscall" "time" appsv1 "k8s.io/api/apps/v1" @@ -78,7 +79,7 @@ func start(ctx context.Context, l net.Listener, handler http.Handler) { func waitForSignal() os.Signal { signalCh := make(chan os.Signal, 1) - signal.Notify(signalCh, os.Interrupt) + signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM) return <-signalCh }