@@ -17,6 +17,8 @@ limitations under the License.
17
17
package job
18
18
19
19
import (
20
+ "fmt"
21
+ "strings"
20
22
"time"
21
23
22
24
batchv1 "k8s.io/api/batch/v1"
@@ -99,22 +101,28 @@ func WaitForJobGone(c clientset.Interface, ns, jobName string, timeout time.Dura
99
101
})
100
102
}
101
103
102
- // CheckForAllJobPodsRunning uses c to check in the Job named jobName in ns is running. If the returned error is not
103
- // nil the returned bool is true if the Job is running.
104
- func CheckForAllJobPodsRunning (c clientset.Interface , ns , jobName string , parallelism int32 ) (bool , error ) {
104
+ // EnsureAllJobPodsRunning uses c to check in the Job named jobName in ns
105
+ // is running, returning an error if the expected parallelism is not
106
+ // satisfied.
107
+ func EnsureAllJobPodsRunning (c clientset.Interface , ns , jobName string , parallelism int32 ) error {
105
108
label := labels .SelectorFromSet (labels .Set (map [string ]string {JobSelectorKey : jobName }))
106
109
options := metav1.ListOptions {LabelSelector : label .String ()}
107
110
pods , err := c .CoreV1 ().Pods (ns ).List (options )
108
111
if err != nil {
109
- return false , err
112
+ return err
110
113
}
114
+ podsSummary := make ([]string , 0 , parallelism )
111
115
count := int32 (0 )
112
116
for _ , p := range pods .Items {
113
117
if p .Status .Phase == v1 .PodRunning {
114
118
count ++
115
119
}
120
+ podsSummary = append (podsSummary , fmt .Sprintf ("%s (%s: %s)" , p .ObjectMeta .Name , p .Status .Phase , p .Status .Message ))
121
+ }
122
+ if count != parallelism {
123
+ return fmt .Errorf ("job has %d of %d expected running pods: %s" , count , parallelism , strings .Join (podsSummary , ", " ))
116
124
}
117
- return count == parallelism , nil
125
+ return nil
118
126
}
119
127
120
128
// WaitForAllJobPodsGone waits for all pods for the Job named jobName in namespace ns
0 commit comments