2 回答
TA贡献1812条经验 获得超5个赞
import corev1 "k8s.io/api/core/v1"
// RestartPod deletes a pod marked by a given label
// it then waits for a given timeout for the pod to resume running state
func RestartPod(c *client.ClientSet, label string, timeout time.Duration) error {
pod, err := GetPodByLabel(label)
if err != nil {
return err
}
podUid := pod.UID
err = c.Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
if err != nil {
return err
}
return wait.PollImmediate(5*time.Second, timeout, func() (done bool, err error) {
pod, err := GetPodByLabel(label)
if pod.UID != podUid && err != nil {
return false, nil
}
return pod.Status.Phase == corev1.PodRunning && pod.Status.ContainerStatuses[0].Ready, nil
})
}
- 2 回答
- 0 关注
- 175 浏览
添加回答
举报