diff --git a/pkg/agent/containerd/containerd.go b/pkg/agent/containerd/containerd.go index 9e542f8fcd..20f6569470 100644 --- a/pkg/agent/containerd/containerd.go +++ b/pkg/agent/containerd/containerd.go @@ -99,10 +99,12 @@ func Run(ctx context.Context, cfg *config.Node) error { cmd.Env = append(env, cenv...) 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) + os.Exit(1) } - os.Exit(1) + os.Exit(0) }() if err := cri.WaitForService(ctx, cfg.Containerd.Address, "containerd"); err != nil { diff --git a/pkg/agent/cridockerd/cridockerd.go b/pkg/agent/cridockerd/cridockerd.go index 2ca681bfcb..b17a5646cc 100644 --- a/pkg/agent/cridockerd/cridockerd.go +++ b/pkg/agent/cridockerd/cridockerd.go @@ -5,6 +5,7 @@ package cridockerd import ( "context" + "errors" "os" "runtime/debug" "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.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") diff --git a/pkg/agent/flannel/setup.go b/pkg/agent/flannel/setup.go index b8b7eb0b0b..16a60048d2 100644 --- a/pkg/agent/flannel/setup.go +++ b/pkg/agent/flannel/setup.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net" + "os" "path/filepath" goruntime "runtime" "strings" @@ -76,8 +77,10 @@ func Run(ctx context.Context, nodeConfig *config.Node, nodes typedcorev1.NodeInt go func() { err := flannel(ctx, nodeConfig.FlannelIface, nodeConfig.FlannelConfFile, nodeConfig.AgentConfig.KubeConfigKubelet, nodeConfig.FlannelIPv6Masq, nodeConfig.MultiClusterCIDR, netMode) 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 diff --git a/pkg/daemons/executor/embed.go b/pkg/daemons/executor/embed.go index 0e02c3fd19..9c6e28467f 100644 --- a/pkg/daemons/executor/embed.go +++ b/pkg/daemons/executor/embed.go @@ -7,6 +7,7 @@ import ( "context" "flag" "net/http" + "os" "runtime" "runtime/debug" "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 { 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 @@ -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.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 @@ -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.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 @@ -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.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 @@ -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.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 @@ -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.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