Merge pull request #29952 from fabianofranz/handle_container_terminated_pod_running_condition

Automatic merge from submit-queue

Handle container terminated but pod still running in conditions

Sometimes when you have a pod with more than one container, and the container runs and terminates really fast, `PodContainerRunning` can go into a state where the pod indicates it's still running, but the container is already terminated. Handle that condition by returning `ErrContainerTerminated` when it happens.
This commit is contained in:
Kubernetes Submit Queue 2016-08-04 07:13:08 -07:00 committed by GitHub
commit c2340870c6

View File

@ -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