Skip to content

Commit 4643f96

Browse files
Merge pull request #463 from kstrenkova/add-pending-state-check
Distinguish pending from running pods
2 parents 17cbdc4 + 11e0c63 commit 4643f96

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

internal/controller/common.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const (
5656
const (
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

internal/controller/common_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ func CommonReconcile[T TestResource](
210210
}
211211

212212
switch nextAction {
213+
case CheckPending:
214+
Log.Info(InfoPendingPod)
215+
return ctrl.Result{RequeueAfter: RequeueAfterValue}, nil
216+
213217
case Wait:
214218
Log.Info(InfoWaitingOnPod)
215219
return ctrl.Result{RequeueAfter: RequeueAfterValue}, nil

0 commit comments

Comments
 (0)