mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #77716 from wking/job-running-test-error-reporting
test/e2e/upgrades/apps/job: List Pods in failure message
This commit is contained in:
commit
bac667ebf4
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user