Skip to content

Commit 2f270bd

Browse files
authored
Merge pull request kubernetes#121017 from kannon92/fix-apps-issue
Remove consistent check in test for job suspend
2 parents b43b95a + 42945ea commit 2f270bd

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

test/e2e/apps/job.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,31 +280,18 @@ var _ = SIGDescribe("Job", func() {
280280
job, err := e2ejob.CreateJob(ctx, f.ClientSet, f.Namespace.Name, job)
281281
framework.ExpectNoError(err, "failed to create job in namespace: %s", f.Namespace.Name)
282282

283-
ginkgo.By("Ensuring pods aren't created for job")
284-
err = framework.Gomega().Consistently(ctx, framework.HandleRetry(func(ctx context.Context) ([]v1.Pod, error) {
285-
pods, err := e2ejob.GetJobPods(ctx, f.ClientSet, f.Namespace.Name, job.Name)
286-
if err != nil {
287-
return nil, fmt.Errorf("failed to list pod for a given job %s in namespace %s: %w", job.Name, f.Namespace.Name, err)
288-
}
289-
return pods.Items, nil
290-
})).WithPolling(framework.Poll).WithTimeout(wait.ForeverTestTimeout).Should(gomega.BeEmpty())
291-
framework.ExpectNoError(err, "failed to confirm that pods aren't created for job %s in namespace %s", job.Name, f.Namespace.Name)
292-
293283
ginkgo.By("Checking Job status to observe Suspended state")
294-
job, err = e2ejob.GetJob(ctx, f.ClientSet, f.Namespace.Name, job.Name)
295-
framework.ExpectNoError(err, "failed to retrieve latest job object")
296-
exists := false
297-
for _, c := range job.Status.Conditions {
298-
if c.Type == batchv1.JobSuspended {
299-
exists = true
300-
break
301-
}
302-
}
303-
if !exists {
304-
framework.Failf("Job was expected to be completed or failed")
305-
}
284+
err = e2ejob.WaitForJobSuspend(ctx, f.ClientSet, f.Namespace.Name, job.Name)
285+
framework.ExpectNoError(err, "failed to observe suspend state: %s", f.Namespace.Name)
286+
287+
ginkgo.By("Ensuring pods aren't created for job")
288+
pods, err := e2ejob.GetJobPods(ctx, f.ClientSet, f.Namespace.Name, job.Name)
289+
framework.ExpectNoError(err, "failed to list pod for a given job %s in namespace %s", job.Name, f.Namespace.Name)
290+
gomega.Expect(pods.Items).To(gomega.BeEmpty())
306291

307292
ginkgo.By("Updating the job with suspend=false")
293+
job, err = f.ClientSet.BatchV1().Jobs(f.Namespace.Name).Get(ctx, job.Name, metav1.GetOptions{})
294+
framework.ExpectNoError(err, "failed to get job in namespace: %s", f.Namespace.Name)
308295
job.Spec.Suspend = pointer.BoolPtr(false)
309296
job, err = e2ejob.UpdateJob(ctx, f.ClientSet, f.Namespace.Name, job)
310297
framework.ExpectNoError(err, "failed to update job in namespace: %s", f.Namespace.Name)

test/e2e/framework/job/wait.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func WaitForJobReady(ctx context.Context, c clientset.Interface, ns, jobName str
8888
})
8989
}
9090

91+
// WaitForJobSuspend uses c to wait for suspend condition for the Job jobName in namespace ns.
92+
func WaitForJobSuspend(ctx context.Context, c clientset.Interface, ns, jobName string) error {
93+
return WaitForJobState(ctx, c, ns, jobName, JobTimeout, func(job *batchv1.Job) string {
94+
for _, c := range job.Status.Conditions {
95+
if c.Type == batchv1.JobSuspended && c.Status == v1.ConditionTrue {
96+
return ""
97+
}
98+
}
99+
return "job should be suspended"
100+
})
101+
}
102+
91103
// WaitForJobFailed uses c to wait for the Job jobName in namespace ns to fail
92104
func WaitForJobFailed(c clientset.Interface, ns, jobName string) error {
93105
return wait.PollImmediate(framework.Poll, JobTimeout, func() (bool, error) {

0 commit comments

Comments
 (0)