diff --git a/vendor.conf b/vendor.conf index 0cdc3200..011529e2 100644 --- a/vendor.conf +++ b/vendor.conf @@ -3,5 +3,5 @@ github.com/rancher/types k8s.io/kubernetes v1.8.3 transitive=true,staging=true bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git -github.com/rancher/norman 9be32ca0a540082e23a24a2b46127b5c205db262 +github.com/rancher/norman 391a96f33dd0b1f893f8b194e2d7cad3e26d1351 golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 diff --git a/vendor/github.com/rancher/norman/signal/sigterm.go b/vendor/github.com/rancher/norman/signal/sigterm.go new file mode 100644 index 00000000..cf2e3b55 --- /dev/null +++ b/vendor/github.com/rancher/norman/signal/sigterm.go @@ -0,0 +1,28 @@ +package signal + +import ( + "context" + "os" + "os/signal" + "syscall" + + "github.com/sirupsen/logrus" +) + +func SigTermCancelContext(ctx context.Context) context.Context { + term := make(chan os.Signal) + signal.Notify(term, os.Interrupt, syscall.SIGTERM) + + ctx, cancel := context.WithCancel(ctx) + + go func() { + select { + case <-term: + logrus.Infof("Received SIGTERM, cancelling") + cancel() + case <-ctx.Done(): + } + }() + + return ctx +}