Skip to content

Commit 8a5df6d

Browse files
authored
Merge pull request #1278 from halaney/ahalaney/fix-sigterm
fix: handle SIGTERM gracefully on unix
2 parents 2513573 + 31d036e commit 8a5df6d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

cmd/nodeproblemdetector/node_problem_detector_unix.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ package main
2121
import (
2222
"context"
2323
"flag"
24+
"os"
25+
"os/signal"
26+
"syscall"
2427

2528
"github.com/spf13/pflag"
2629
"k8s.io/klog/v2"
@@ -54,7 +57,9 @@ func main() {
5457
}
5558

5659
pflag.Parse()
57-
if err := npdMain(context.Background(), npdo); err != nil {
60+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
61+
defer stop()
62+
if err := npdMain(ctx, npdo); err != nil {
5863
klog.Fatalf("Problem detector failed with error: %v", err)
5964
}
6065
}

0 commit comments

Comments
 (0)