Watch kubernetes pod status to be completed in client-go

前端 未结 2 1214
别跟我提以往
别跟我提以往 2020-12-16 23:22

I am creating a pod in k8 client go and making a watch to get notified for when the pod has completed so that i can read the logs of the pod. The watch interface doesnt seem

2条回答
  •  抹茶落季
    2020-12-17 00:04

    You keep could keep checking the pod status in a loop and whenever the status changes to successful, you're done

    for {
        pod, _ := clientset.CoreV1().Pods(Namespace).Get(podName, metav1.GetOptions{})
        if pod.Status.Phase != corev1.PodPending {
            break
        }
    }
    pod, _ := clientset.CoreV1().Pods(corev1.NamespaceDefault).Get(podName, metav1.GetOptions{})
    if pod.Status.Phase != corev1.PodSucceeded {
        return false, fmt.Errorf("Pod did not succeed/complete")
    }
    return true, nil
    

提交回复
热议问题