mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-25 11:31:44 +00:00
Merge pull request #31474 from janetkuo/sj-e2e-list-only-running-jobs
Automatic merge from submit-queue In SJ e2e test, check only running jobs We should filter "running" jobs in SJ e2e test **Release note**: <!-- Steps to write your release note: 1. Use the release-note-* labels to set the release note state (if you have access) 2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. --> ```release-note NONE ``` cc @erictune @soltysh
This commit is contained in:
commit
02382e7273
@ -65,10 +65,11 @@ var _ = framework.KubeDescribe("ScheduledJob", func() {
|
|||||||
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 2)
|
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 2)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("Ensuring exactly two jobs exists by listing jobs explicitly")
|
By("Ensuring at least two running jobs exists by listing jobs explicitly")
|
||||||
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(jobs.Items) >= 2).To(BeTrue())
|
activeJobs := filterActiveJobs(jobs)
|
||||||
|
Expect(len(activeJobs) >= 2).To(BeTrue())
|
||||||
|
|
||||||
By("Removing scheduledjob")
|
By("Removing scheduledjob")
|
||||||
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name)
|
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name)
|
||||||
@ -113,10 +114,11 @@ var _ = framework.KubeDescribe("ScheduledJob", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(scheduledJob.Status.Active).Should(HaveLen(1))
|
Expect(scheduledJob.Status.Active).Should(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring exaclty one job exists by listing jobs explicitly")
|
By("Ensuring exaclty one running job exists by listing jobs explicitly")
|
||||||
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(jobs.Items).To(HaveLen(1))
|
activeJobs := filterActiveJobs(jobs)
|
||||||
|
Expect(activeJobs).To(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring no more jobs are scheduled")
|
By("Ensuring no more jobs are scheduled")
|
||||||
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 2)
|
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 2)
|
||||||
@ -143,10 +145,11 @@ var _ = framework.KubeDescribe("ScheduledJob", func() {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(scheduledJob.Status.Active).Should(HaveLen(1))
|
Expect(scheduledJob.Status.Active).Should(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring exaclty one job exists by listing jobs explicitly")
|
By("Ensuring exaclty one running job exists by listing jobs explicitly")
|
||||||
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{})
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(jobs.Items).To(HaveLen(1))
|
activeJobs := filterActiveJobs(jobs)
|
||||||
|
Expect(activeJobs).To(HaveLen(1))
|
||||||
|
|
||||||
By("Ensuring the job is replaced with a new one")
|
By("Ensuring the job is replaced with a new one")
|
||||||
err = waitForJobReplaced(f.Client, f.Namespace.Name, jobs.Items[0].Name)
|
err = waitForJobReplaced(f.Client, f.Namespace.Name, jobs.Items[0].Name)
|
||||||
@ -324,3 +327,13 @@ func checkNoUnexpectedEvents(c *client.Client, ns, scheduledJobName string) erro
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterActiveJobs(jobs *batch.JobList) (active []*batch.Job) {
|
||||||
|
for i := range jobs.Items {
|
||||||
|
j := jobs.Items[i]
|
||||||
|
if !job.IsJobFinished(&j) {
|
||||||
|
active = append(active, &j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user