diff --git a/test/e2e/framework/job/wait.go b/test/e2e/framework/job/wait.go index d74509e6cb7..8df3b60cd6c 100644 --- a/test/e2e/framework/job/wait.go +++ b/test/e2e/framework/job/wait.go @@ -17,6 +17,8 @@ limitations under the License. package job import ( + "fmt" + "strings" "time" batchv1 "k8s.io/api/batch/v1" @@ -99,22 +101,28 @@ func WaitForJobGone(c clientset.Interface, ns, jobName string, timeout time.Dura }) } -// CheckForAllJobPodsRunning uses c to check in the Job named jobName in ns is running. If the returned error is not -// nil the returned bool is true if the Job is running. -func CheckForAllJobPodsRunning(c clientset.Interface, ns, jobName string, parallelism int32) (bool, error) { +// EnsureAllJobPodsRunning uses c to check in the Job named jobName in ns +// is running, returning an error if the expected parallelism is not +// satisfied. +func EnsureAllJobPodsRunning(c clientset.Interface, ns, jobName string, parallelism int32) error { label := labels.SelectorFromSet(labels.Set(map[string]string{JobSelectorKey: jobName})) options := metav1.ListOptions{LabelSelector: label.String()} pods, err := c.CoreV1().Pods(ns).List(options) if err != nil { - return false, err + return err } + podsSummary := make([]string, 0, parallelism) count := int32(0) for _, p := range pods.Items { if p.Status.Phase == v1.PodRunning { count++ } + podsSummary = append(podsSummary, fmt.Sprintf("%s (%s: %s)", p.ObjectMeta.Name, p.Status.Phase, p.Status.Message)) } - return count == parallelism, nil + if count != parallelism { + return fmt.Errorf("job has %d of %d expected running pods: %s", count, parallelism, strings.Join(podsSummary, ", ")) + } + return nil } // WaitForAllJobPodsGone waits for all pods for the Job named jobName in namespace ns diff --git a/test/e2e/upgrades/apps/job.go b/test/e2e/upgrades/apps/job.go index 15eacd96356..cd836e75c05 100644 --- a/test/e2e/upgrades/apps/job.go +++ b/test/e2e/upgrades/apps/job.go @@ -55,9 +55,8 @@ func (t *JobUpgradeTest) Setup(f *framework.Framework) { func (t *JobUpgradeTest) Test(f *framework.Framework, done <-chan struct{}, upgrade upgrades.UpgradeType) { <-done ginkgo.By("Ensuring active pods == parallelism") - running, err := jobutil.CheckForAllJobPodsRunning(f.ClientSet, t.namespace, t.job.Name, 2) + err := jobutil.EnsureAllJobPodsRunning(f.ClientSet, t.namespace, t.job.Name, 2) gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect(running).To(gomega.BeTrue()) } // Teardown cleans up any remaining resources.