mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Consistently handle component exit on shutdown
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
9e076db724
commit
753c00f30c
@ -99,10 +99,12 @@ func Run(ctx context.Context, cfg *config.Node) error {
|
|||||||
cmd.Env = append(env, cenv...)
|
cmd.Env = append(env, cenv...)
|
||||||
|
|
||||||
addDeathSig(cmd)
|
addDeathSig(cmd)
|
||||||
if err := cmd.Run(); err != nil {
|
err := cmd.Run()
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
logrus.Errorf("containerd exited: %s", err)
|
logrus.Errorf("containerd exited: %s", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
os.Exit(1)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := cri.WaitForService(ctx, cfg.Containerd.Address, "containerd"); err != nil {
|
if err := cri.WaitForService(ctx, cfg.Containerd.Address, "containerd"); err != nil {
|
||||||
|
@ -5,6 +5,7 @@ package cridockerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
@ -37,7 +38,12 @@ func Run(ctx context.Context, cfg *config.Node) error {
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("cri-dockerd panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("cri-dockerd panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Fatalf("cri-dockerd exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("cri-dockerd exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return cri.WaitForService(ctx, cfg.CRIDockerd.Address, "cri-dockerd")
|
return cri.WaitForService(ctx, cfg.CRIDockerd.Address, "cri-dockerd")
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -76,8 +77,10 @@ func Run(ctx context.Context, nodeConfig *config.Node, nodes typedcorev1.NodeInt
|
|||||||
go func() {
|
go func() {
|
||||||
err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, nodeConfig.AgentConfig.KubeConfigKubelet, nodeConfig.FlannelIPv6Masq, netMode)
|
err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, nodeConfig.AgentConfig.KubeConfigKubelet, nodeConfig.FlannelIPv6Masq, netMode)
|
||||||
if err != nil && !errors.Is(err, context.Canceled) {
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
logrus.Fatalf("flannel exited: %v", err)
|
logrus.Errorf("flannel exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -90,7 +91,12 @@ func (e *Embedded) Kubelet(ctx context.Context, args []string) error {
|
|||||||
if err := util.WaitForAPIServerReady(ctx, e.nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil {
|
if err := util.WaitForAPIServerReady(ctx, e.nodeConfig.AgentConfig.KubeConfigKubelet, util.DefaultAPIServerReadyTimeout); err != nil {
|
||||||
logrus.Fatalf("Kubelet failed to wait for apiserver ready: %v", err)
|
logrus.Fatalf("Kubelet failed to wait for apiserver ready: %v", err)
|
||||||
}
|
}
|
||||||
logrus.Fatalf("kubelet exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("kubelet exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -106,7 +112,12 @@ func (e *Embedded) KubeProxy(ctx context.Context, args []string) error {
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("kube-proxy panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("kube-proxy panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Fatalf("kube-proxy exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("kube-proxy exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -128,7 +139,12 @@ func (*Embedded) APIServer(ctx context.Context, etcdReady <-chan struct{}, args
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("apiserver panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("apiserver panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Fatalf("apiserver exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("apiserver exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -157,7 +173,12 @@ func (e *Embedded) Scheduler(ctx context.Context, apiReady <-chan struct{}, args
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("scheduler panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("scheduler panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Fatalf("scheduler exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("scheduler exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -174,7 +195,12 @@ func (*Embedded) ControllerManager(ctx context.Context, apiReady <-chan struct{}
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("controller-manager panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("controller-manager panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Fatalf("controller-manager exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("controller-manager exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -215,7 +241,12 @@ func (*Embedded) CloudControllerManager(ctx context.Context, ccmRBACReady <-chan
|
|||||||
logrus.WithField("stack", string(debug.Stack())).Fatalf("cloud-controller-manager panic: %v", err)
|
logrus.WithField("stack", string(debug.Stack())).Fatalf("cloud-controller-manager panic: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
logrus.Errorf("cloud-controller-manager exited: %v", command.ExecuteContext(ctx))
|
err := command.ExecuteContext(ctx)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
logrus.Errorf("cloud-controller-manager exited: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user