code: func checkContainerStateTransition(oldStatuses, newStatuses []v1.ContainerStatus, restartPolicy v1.RestartPolicy) error {
  	// If we should always restart, containers are allowed to leave the terminated state
  	if restartPolicy == v1.RestartPolicyAlways {
  		return nil
  	}
  	for _, oldStatus := range oldStatuses {
  		// Skip any container that wasn't terminated
  		if oldStatus.State.Terminated == nil {
  			continue
  		}
  		// Skip any container that failed but is allowed to restart
  		if oldStatus.State.Terminated.ExitCode != 0 && restartPolicy == v1.RestartPolicyOnFailure {
  			continue
  		}
  		for _, newStatus := range newStatuses {
  			if oldStatus.Name == newStatus.Name && newStatus.State.Terminated == nil {
  				return fmt.Errorf("terminated container %v attempted illegal transition to non-terminated state", newStatus.Name)
  			}
  		}
  	}
  	return nil
  }
docs: // checkContainerStateTransition ensures that no container is trying to transition
  // from a terminated to non-terminated state, which is illegal and indicates a
  // logical error in the kubelet.