Skip to content

Commit

Permalink
Merge pull request #44 from GMH233/hotfix/runtime
Browse files Browse the repository at this point in the history
fix: restart pod
  • Loading branch information
sjtuzc954 authored May 29, 2024
2 parents dcbdb9a + a5de601 commit 296fd2d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pkg/kubelet/runtime/runtime_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 296fd2d

Please sign in to comment.