|
|
@ -235,6 +235,8 @@ func (c *Client) watchTimeout(t time.Duration) func(*resource.Info) error {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// - Jobs: A job is marked "Ready" when it has successfully completed. This is
|
|
|
|
// - Jobs: A job is marked "Ready" when it has successfully completed. This is
|
|
|
|
// ascertained by watching the Status fields in a job's output.
|
|
|
|
// ascertained by watching the Status fields in a job's output.
|
|
|
|
|
|
|
|
// - Pods: A pod is marked "Ready" when it has successfully completed. This is
|
|
|
|
|
|
|
|
// ascertained by watching the status.phase field in a pod's output.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Handling for other kinds will be added as necessary.
|
|
|
|
// Handling for other kinds will be added as necessary.
|
|
|
|
func (c *Client) WatchUntilReady(resources ResourceList, timeout time.Duration) error {
|
|
|
|
func (c *Client) WatchUntilReady(resources ResourceList, timeout time.Duration) error {
|
|
|
@ -383,8 +385,11 @@ func (c *Client) watchUntilReady(timeout time.Duration, info *resource.Info) err
|
|
|
|
// the status go into a good state. For other types, like ReplicaSet
|
|
|
|
// the status go into a good state. For other types, like ReplicaSet
|
|
|
|
// we don't really do anything to support these as hooks.
|
|
|
|
// we don't really do anything to support these as hooks.
|
|
|
|
c.Log("Add/Modify event for %s: %v", info.Name, e.Type)
|
|
|
|
c.Log("Add/Modify event for %s: %v", info.Name, e.Type)
|
|
|
|
if kind == "Job" {
|
|
|
|
switch kind {
|
|
|
|
|
|
|
|
case "Job":
|
|
|
|
return c.waitForJob(obj, info.Name)
|
|
|
|
return c.waitForJob(obj, info.Name)
|
|
|
|
|
|
|
|
case "Pod":
|
|
|
|
|
|
|
|
return c.waitForPodSuccess(obj, info.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
return true, nil
|
|
|
|
case watch.Deleted:
|
|
|
|
case watch.Deleted:
|
|
|
@ -422,6 +427,30 @@ func (c *Client) waitForJob(obj runtime.Object, name string) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// waitForPodSuccess is a helper that waits for a pod to complete.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// This operates on an event returned from a watcher.
|
|
|
|
|
|
|
|
func (c *Client) waitForPodSuccess(obj runtime.Object, name string) (bool, error) {
|
|
|
|
|
|
|
|
o, ok := obj.(*v1.Pod)
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
|
|
return true, errors.Errorf("expected %s to be a *v1.Pod, got %T", name, obj)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch o.Status.Phase {
|
|
|
|
|
|
|
|
case v1.PodSucceeded:
|
|
|
|
|
|
|
|
fmt.Printf("Pod %s succeeded\n", o.Name)
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
|
|
|
|
case v1.PodFailed:
|
|
|
|
|
|
|
|
return true, errors.Errorf("pod %s failed", o.Name)
|
|
|
|
|
|
|
|
case v1.PodPending:
|
|
|
|
|
|
|
|
fmt.Printf("Pod %s pending\n", o.Name)
|
|
|
|
|
|
|
|
case v1.PodRunning:
|
|
|
|
|
|
|
|
fmt.Printf("Pod %s running\n", o.Name)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// scrubValidationError removes kubectl info from the message.
|
|
|
|
// scrubValidationError removes kubectl info from the message.
|
|
|
|
func scrubValidationError(err error) error {
|
|
|
|
func scrubValidationError(err error) error {
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|