Skip to content

Commit bac667e

Browse files
authored
Merge pull request kubernetes#77716 from wking/job-running-test-error-reporting
test/e2e/upgrades/apps/job: List Pods in failure message
2 parents 07e3b7c + 96b04bf commit bac667e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

test/e2e/framework/job/wait.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package job
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"time"
2123

2224
batchv1 "k8s.io/api/batch/v1"
@@ -99,22 +101,28 @@ func WaitForJobGone(c clientset.Interface, ns, jobName string, timeout time.Dura
99101
})
100102
}
101103

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 {
105108
label := labels.SelectorFromSet(labels.Set(map[string]string{JobSelectorKey: jobName}))
106109
options := metav1.ListOptions{LabelSelector: label.String()}
107110
pods, err := c.CoreV1().Pods(ns).List(options)
108111
if err != nil {
109-
return false, err
112+
return err
110113
}
114+
podsSummary := make([]string, 0, parallelism)
111115
count := int32(0)
112116
for _, p := range pods.Items {
113117
if p.Status.Phase == v1.PodRunning {
114118
count++
115119
}
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, ", "))
116124
}
117-
return count == parallelism, nil
125+
return nil
118126
}
119127

120128
// WaitForAllJobPodsGone waits for all pods for the Job named jobName in namespace ns

test/e2e/upgrades/apps/job.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ func (t *JobUpgradeTest) Setup(f *framework.Framework) {
5555
func (t *JobUpgradeTest) Test(f *framework.Framework, done <-chan struct{}, upgrade upgrades.UpgradeType) {
5656
<-done
5757
ginkgo.By("Ensuring active pods == parallelism")
58-
running, err := jobutil.CheckForAllJobPodsRunning(f.ClientSet, t.namespace, t.job.Name, 2)
58+
err := jobutil.EnsureAllJobPodsRunning(f.ClientSet, t.namespace, t.job.Name, 2)
5959
gomega.Expect(err).NotTo(gomega.HaveOccurred())
60-
gomega.Expect(running).To(gomega.BeTrue())
6160
}
6261

6362
// Teardown cleans up any remaining resources.

0 commit comments

Comments
 (0)