mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Job: Fix CronJob e2e test for async Job deletion.
Now that the default delete option for Job is OrphanDependents, Job deletion is asynchronous.
This commit is contained in:
parent
c82b537bee
commit
e207f6c767
@ -124,7 +124,7 @@ var _ = framework.KubeDescribe("CronJob", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(cronJob.Status.Active).Should(HaveLen(1))
|
Expect(cronJob.Status.Active).Should(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring exaclty one running job exists by listing jobs explicitly")
|
By("Ensuring exactly one running job exists by listing jobs explicitly")
|
||||||
jobs, err := f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
|
jobs, err := f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
activeJobs, _ := filterActiveJobs(jobs)
|
activeJobs, _ := filterActiveJobs(jobs)
|
||||||
@ -156,7 +156,7 @@ var _ = framework.KubeDescribe("CronJob", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(cronJob.Status.Active).Should(HaveLen(1))
|
Expect(cronJob.Status.Active).Should(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring exaclty one running job exists by listing jobs explicitly")
|
By("Ensuring exactly one running job exists by listing jobs explicitly")
|
||||||
jobs, err := f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
|
jobs, err := f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
activeJobs, _ := filterActiveJobs(jobs)
|
activeJobs, _ := filterActiveJobs(jobs)
|
||||||
@ -394,13 +394,15 @@ func waitForJobReplaced(c clientset.Interface, ns, previousJobName string) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if len(jobs.Items) > 1 {
|
// Ignore Jobs pending deletion, since deletion of Jobs is now asynchronous.
|
||||||
|
aliveJobs := filterNotDeletedJobs(jobs)
|
||||||
|
if len(aliveJobs) > 1 {
|
||||||
return false, fmt.Errorf("More than one job is running %+v", jobs.Items)
|
return false, fmt.Errorf("More than one job is running %+v", jobs.Items)
|
||||||
} else if len(jobs.Items) == 0 {
|
} else if len(aliveJobs) == 0 {
|
||||||
framework.Logf("Warning: Found 0 jobs in namespace %v", ns)
|
framework.Logf("Warning: Found 0 jobs in namespace %v", ns)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return jobs.Items[0].Name != previousJobName, nil
|
return aliveJobs[0].Name != previousJobName, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,6 +453,19 @@ func checkNoEventWithReason(c clientset.Interface, ns, cronJobName string, reaso
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filterNotDeletedJobs returns the job list without any jobs that are pending
|
||||||
|
// deletion.
|
||||||
|
func filterNotDeletedJobs(jobs *batchv1.JobList) []*batchv1.Job {
|
||||||
|
var alive []*batchv1.Job
|
||||||
|
for i := range jobs.Items {
|
||||||
|
job := &jobs.Items[i]
|
||||||
|
if job.DeletionTimestamp == nil {
|
||||||
|
alive = append(alive, job)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return alive
|
||||||
|
}
|
||||||
|
|
||||||
func filterActiveJobs(jobs *batchv1.JobList) (active []*batchv1.Job, finished []*batchv1.Job) {
|
func filterActiveJobs(jobs *batchv1.JobList) (active []*batchv1.Job, finished []*batchv1.Job) {
|
||||||
for i := range jobs.Items {
|
for i := range jobs.Items {
|
||||||
j := jobs.Items[i]
|
j := jobs.Items[i]
|
||||||
|
Loading…
Reference in New Issue
Block a user