Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/e2e/upgrades/apps/job: List Pods in failure message #77716

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions test/e2e/framework/job/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package job

import (
"fmt"
"strings"
"time"

batchv1 "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -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))
}
if count != parallelism {
return fmt.Errorf("job has %d of %d expected running pods: %s", count, parallelism, strings.Join(podsSummary, ", "))
}
return count == parallelism, nil
return nil
}

// WaitForAllJobPodsGone waits for all pods for the Job named jobName in namespace ns
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/upgrades/apps/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down