diff --git a/pkg/cmd/cli/cmd/debug.go b/pkg/cmd/cli/cmd/debug.go index 79f9404529de..bf3f109b8dbb 100644 --- a/pkg/cmd/cli/cmd/debug.go +++ b/pkg/cmd/cli/cmd/debug.go @@ -344,6 +344,7 @@ func (o *DebugOptions) Debug() error { return err } fmt.Fprintf(o.Attach.Err, "Waiting for pod to start ...\n") + switch containerRunningEvent, err := watch.Until(o.Timeout, w, kclient.PodContainerRunning(o.Attach.ContainerName)); { // api didn't error right away but the pod wasn't even created case kapierrors.IsNotFound(err): @@ -352,8 +353,8 @@ func (o *DebugOptions) Debug() error { msg += fmt.Sprintf(" on node %q", o.NodeName) } return fmt.Errorf(msg) - // switch to logging output - case err == kclient.ErrPodCompleted, !o.Attach.Stdin: + // switch to logging output + case err == kclient.ErrPodCompleted, err == kclient.ErrContainerTerminated, !o.Attach.Stdin: _, err := kcmd.LogsOptions{ Object: pod, Options: &kapi.PodLogOptions{ diff --git a/vendor/k8s.io/kubernetes/pkg/client/unversioned/conditions.go b/vendor/k8s.io/kubernetes/pkg/client/unversioned/conditions.go index f68f98fe121e..143fd4c70d14 100644 --- a/vendor/k8s.io/kubernetes/pkg/client/unversioned/conditions.go +++ b/vendor/k8s.io/kubernetes/pkg/client/unversioned/conditions.go @@ -121,6 +121,10 @@ func DeploymentHasDesiredReplicas(c ExtensionsInterface, deployment *extensions. // the pod has already reached completed state. var ErrPodCompleted = fmt.Errorf("pod ran to completion") +// ErrContainerTerminated is returned by PodContainerRunning in the intermediate +// state where the pod indicates it's still running, but its container is already terminated +var ErrContainerTerminated = fmt.Errorf("container terminated") + // PodRunning returns true if the pod is running, false if the pod has not yet reached running state, // returns ErrPodCompleted if the pod has run to completion, or an error in any other case. func PodRunning(event watch.Event) (bool, error) { @@ -217,6 +221,9 @@ func PodContainerRunning(containerName string) watch.ConditionFunc { if s.Name != containerName { continue } + if s.State.Terminated != nil { + return false, ErrContainerTerminated + } return s.State.Running != nil, nil } return false, nil