@@ -56,6 +56,8 @@ const (
5656const (
5757 // InfoWaitingOnPod is the info message when waiting for pod completion or lock release
5858 InfoWaitingOnPod = "Waiting on either pod to finish or release of the lock."
59+ // InfoPendingPod is the info message when waiting for a pending pod to start
60+ InfoPendingPod = "Waiting for pending pod to start running."
5961 // InfoTestingCompleted is the info message when all testing is completed
6062 InfoTestingCompleted = "Testing completed. All pods spawned by the test-operator finished."
6163 // InfoCreatingFirstPod is the info message when creating the first test pod
@@ -117,6 +119,10 @@ const (
117119 // to change
118120 Wait = iota
119121
122+ // CheckPending indicates that the pod is pending and prerequisite checks
123+ // should be run on each reconcile to catch early failures
124+ CheckPending
125+
120126 // CreateFirstPod indicates that the Reconcile loop should create the first pod
121127 // either specified in the .Spec section or in the .Spec.Workflow section.
122128 CreateFirstPod
@@ -197,23 +203,29 @@ func (r *Reconciler) NextAction(
197203 return Failure , workflowStepIdx , err
198204 }
199205
200- // If the last pod is not in Failed or Succeeded state -> Wait
201- lastPodFinished := lastPod .Status .Phase == corev1 .PodFailed || lastPod .Status .Phase == corev1 .PodSucceeded
202- if ! lastPodFinished {
206+ switch lastPod .Status .Phase {
207+ case corev1 .PodPending :
208+ // If the last pod is in Pending state -> CheckPending
209+ return CheckPending , workflowStepIdx , nil
210+
211+ case corev1 .PodRunning :
212+ // If the last pod is in Running state -> Wait
203213 return Wait , workflowStepIdx , nil
204- }
205214
206- // If the last pod is in Failed or Succeeded state and it is NOT the last
207- // pod which was supposed to be created -> CreateNextPod
208- if lastPodFinished && ! isLastPodIndex (workflowStepIdx , workflowLength ) {
209- workflowStepIdx ++
210- return CreateNextPod , workflowStepIdx , nil
211- }
215+ case corev1 .PodFailed , corev1 .PodSucceeded :
216+ // If the last pod is finished and it is NOT the last pod which was
217+ // supposed to be created -> CreateNextPod
218+ if ! isLastPodIndex (workflowStepIdx , workflowLength ) {
219+ workflowStepIdx ++
220+ return CreateNextPod , workflowStepIdx , nil
221+ }
212222
213- // Otherwise if the pod is in Failed or Succeeded state and it IS the
214- // last pod -> EndTesting
215- if lastPodFinished && isLastPodIndex (workflowStepIdx , workflowLength ) {
223+ // Otherwise if the pod is finished and it IS the last pod -> EndTesting
216224 return EndTesting , workflowStepIdx , nil
225+
226+ default :
227+ // If the last pod is in Unknown state -> Wait
228+ return Wait , workflowStepIdx , nil
217229 }
218230 }
219231
0 commit comments