diff --git a/pkg/kubelet/runtime/runtime_manager.go b/pkg/kubelet/runtime/runtime_manager.go index d40aee4..47d0536 100644 --- a/pkg/kubelet/runtime/runtime_manager.go +++ b/pkg/kubelet/runtime/runtime_manager.go @@ -658,14 +658,35 @@ func (rm *runtimeManager) deleteContainer(ct types.Container) error { } func (rm *runtimeManager) RestartPod(pod *v1.Pod) error { - err := rm.DeletePod(pod.UID) + //err := rm.DeletePod(pod.UID) + //if err != nil { + // return err + //} + //err = rm.AddPod(pod) + //if err != nil { + // return err + //} + //return nil + rm.lock.Lock() + defer rm.lock.Unlock() + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { return err } - err = rm.AddPod(pod) + defer cli.Close() + containers, err := rm.getAllContainers() if err != nil { return err } + noWaitTimeout := 0 + for _, ct := range containers { + if ct.Labels["PodID"] == string(pod.UID) { + err = cli.ContainerRestart(context.Background(), ct.ID, container.StopOptions{Timeout: &noWaitTimeout}) + if err != nil { + return err + } + } + } return nil }