
编写
Operator
的方案
|
145
// Try to see if the pod already exists and if not
// (which we expect) then create a one-shot pod as per spec:
found, err := c.kubeClientset.CoreV1().Pods(pod.Namespace).
Get(pod.Name, metav1.GetOptions{})
if err != nil && errors.IsNotFound(err) {
found, err = c.kubeClientset.CoreV1().Pods(pod.Namespace).Create(pod)
if err != nil {
return time.Duration(0), err
}
klog.Infof("instance %s: pod launched: name=%s", key, pod.Name)
} else if err != nil {
// requeue with error
return time.Duration(0), err
} else if found.Status.Phase == corev1.PodFailed ||
found.Status.Phase == corev1.PodSucceeded ...