Merge pull request #31957 from soltysh/sj_e2e_gke

Automatic merge from submit-queue

Check server version when running scheduled job e2e tests

@janetkuo this is the promised followup to #30575 which is checking minimal server version when running ScheduledJob e2e's.
This commit is contained in:
Kubernetes Submit Queue 2016-09-03 09:11:10 -07:00 committed by GitHub
commit bbc6f45e03

View File

@ -24,12 +24,12 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/batch" "k8s.io/kubernetes/pkg/apis/batch"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller/job" "k8s.io/kubernetes/pkg/controller/job"
"k8s.io/kubernetes/pkg/util/wait" "k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
) )
@ -38,7 +38,15 @@ const (
scheduledJobTimeout = 5 * time.Minute scheduledJobTimeout = 5 * time.Minute
) )
var (
// ScheduledJobs were introduced in v1.4, so we don't expect tests that rely on
// ScheduledJobs to work on clusters before that.
scheduledJobsVersion = version.MustParse("v1.4.0-alpha.3")
)
var _ = framework.KubeDescribe("ScheduledJob", func() { var _ = framework.KubeDescribe("ScheduledJob", func() {
defer GinkgoRecover()
options := framework.FrameworkOptions{ options := framework.FrameworkOptions{
ClientQPS: 20, ClientQPS: 20,
ClientBurst: 50, ClientBurst: 50,
@ -46,139 +54,148 @@ var _ = framework.KubeDescribe("ScheduledJob", func() {
} }
f := framework.NewFramework("scheduledjob", options, nil) f := framework.NewFramework("scheduledjob", options, nil)
var c *client.Client
var ns string
BeforeEach(func() { BeforeEach(func() {
if _, err := f.Client.Batch().ScheduledJobs(f.Namespace.Name).List(api.ListOptions{}); err != nil { c = f.Client
if apierrs.IsNotFound(err) { ns = f.Namespace.Name
framework.Skipf("Could not find ScheduledJobs resource, skipping test: %#v", err)
}
}
}) })
// multiple jobs running at once // multiple jobs running at once
It("should schedule multiple jobs concurrently", func() { It("should schedule multiple jobs concurrently", func() {
framework.SkipUnlessServerVersionGTE(scheduledJobsVersion, c)
By("Creating a scheduledjob") By("Creating a scheduledjob")
scheduledJob := newTestScheduledJob("concurrent", "*/1 * * * ?", batch.AllowConcurrent, true) scheduledJob := newTestScheduledJob("concurrent", "*/1 * * * ?", batch.AllowConcurrent, true)
scheduledJob, err := createScheduledJob(f.Client, f.Namespace.Name, scheduledJob) scheduledJob, err := createScheduledJob(c, ns, scheduledJob)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring more than one job is running at a time") By("Ensuring more than one job is running at a time")
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 2) err = waitForActiveJobs(c, ns, scheduledJob.Name, 2)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring at least two running 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 := c.Batch().Jobs(ns).List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
activeJobs := filterActiveJobs(jobs) activeJobs := filterActiveJobs(jobs)
Expect(len(activeJobs) >= 2).To(BeTrue()) Expect(len(activeJobs) >= 2).To(BeTrue())
By("Removing scheduledjob") By("Removing scheduledjob")
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) err = deleteScheduledJob(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
// suspended should not schedule jobs // suspended should not schedule jobs
It("should not schedule jobs when suspended [Slow]", func() { It("should not schedule jobs when suspended [Slow]", func() {
framework.SkipUnlessServerVersionGTE(scheduledJobsVersion, c)
By("Creating a suspended scheduledjob") By("Creating a suspended scheduledjob")
scheduledJob := newTestScheduledJob("suspended", "*/1 * * * ?", batch.AllowConcurrent, true) scheduledJob := newTestScheduledJob("suspended", "*/1 * * * ?", batch.AllowConcurrent, true)
scheduledJob.Spec.Suspend = newBool(true) scheduledJob.Spec.Suspend = newBool(true)
scheduledJob, err := createScheduledJob(f.Client, f.Namespace.Name, scheduledJob) scheduledJob, err := createScheduledJob(c, ns, scheduledJob)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring no jobs are scheduled") By("Ensuring no jobs are scheduled")
err = waitForNoJobs(f.Client, f.Namespace.Name, scheduledJob.Name) err = waitForNoJobs(c, ns, scheduledJob.Name)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
By("Ensuring no job exists by listing jobs explicitly") By("Ensuring no job exists by listing jobs explicitly")
jobs, err := f.Client.Batch().Jobs(f.Namespace.Name).List(api.ListOptions{}) jobs, err := c.Batch().Jobs(ns).List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(jobs.Items).To(HaveLen(0)) Expect(jobs.Items).To(HaveLen(0))
By("Removing scheduledjob") By("Removing scheduledjob")
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) err = deleteScheduledJob(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
// only single active job is allowed for ForbidConcurrent // only single active job is allowed for ForbidConcurrent
It("should not schedule new jobs when ForbidConcurrent [Slow]", func() { It("should not schedule new jobs when ForbidConcurrent [Slow]", func() {
framework.SkipUnlessServerVersionGTE(scheduledJobsVersion, c)
By("Creating a ForbidConcurrent scheduledjob") By("Creating a ForbidConcurrent scheduledjob")
scheduledJob := newTestScheduledJob("forbid", "*/1 * * * ?", batch.ForbidConcurrent, true) scheduledJob := newTestScheduledJob("forbid", "*/1 * * * ?", batch.ForbidConcurrent, true)
scheduledJob, err := createScheduledJob(f.Client, f.Namespace.Name, scheduledJob) scheduledJob, err := createScheduledJob(c, ns, scheduledJob)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring a job is scheduled") By("Ensuring a job is scheduled")
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 1) err = waitForActiveJobs(c, ns, scheduledJob.Name, 1)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring exactly one is scheduled") By("Ensuring exactly one is scheduled")
scheduledJob, err = getScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) scheduledJob, err = getScheduledJob(c, ns, scheduledJob.Name)
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 running 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 := c.Batch().Jobs(ns).List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
activeJobs := filterActiveJobs(jobs) activeJobs := filterActiveJobs(jobs)
Expect(activeJobs).To(HaveLen(1)) 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(c, ns, scheduledJob.Name, 2)
Expect(err).To(HaveOccurred()) Expect(err).To(HaveOccurred())
By("Removing scheduledjob") By("Removing scheduledjob")
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) err = deleteScheduledJob(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
// only single active job is allowed for ReplaceConcurrent // only single active job is allowed for ReplaceConcurrent
It("should replace jobs when ReplaceConcurrent", func() { It("should replace jobs when ReplaceConcurrent", func() {
framework.SkipUnlessServerVersionGTE(scheduledJobsVersion, c)
By("Creating a ReplaceConcurrent scheduledjob") By("Creating a ReplaceConcurrent scheduledjob")
scheduledJob := newTestScheduledJob("replace", "*/1 * * * ?", batch.ReplaceConcurrent, true) scheduledJob := newTestScheduledJob("replace", "*/1 * * * ?", batch.ReplaceConcurrent, true)
scheduledJob, err := createScheduledJob(f.Client, f.Namespace.Name, scheduledJob) scheduledJob, err := createScheduledJob(c, ns, scheduledJob)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring a job is scheduled") By("Ensuring a job is scheduled")
err = waitForActiveJobs(f.Client, f.Namespace.Name, scheduledJob.Name, 1) err = waitForActiveJobs(c, ns, scheduledJob.Name, 1)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring exactly one is scheduled") By("Ensuring exactly one is scheduled")
scheduledJob, err = getScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) scheduledJob, err = getScheduledJob(c, ns, scheduledJob.Name)
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 running 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 := c.Batch().Jobs(ns).List(api.ListOptions{})
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
activeJobs := filterActiveJobs(jobs) activeJobs := filterActiveJobs(jobs)
Expect(activeJobs).To(HaveLen(1)) 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(c, ns, jobs.Items[0].Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Removing scheduledjob") By("Removing scheduledjob")
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) err = deleteScheduledJob(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
// shouldn't give us unexpected warnings // shouldn't give us unexpected warnings
It("should not emit unexpected warnings", func() { It("should not emit unexpected warnings", func() {
framework.SkipUnlessServerVersionGTE(scheduledJobsVersion, c)
By("Creating a scheduledjob") By("Creating a scheduledjob")
scheduledJob := newTestScheduledJob("concurrent", "*/1 * * * ?", batch.AllowConcurrent, false) scheduledJob := newTestScheduledJob("concurrent", "*/1 * * * ?", batch.AllowConcurrent, false)
scheduledJob, err := createScheduledJob(f.Client, f.Namespace.Name, scheduledJob) scheduledJob, err := createScheduledJob(c, ns, scheduledJob)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring at least two jobs and at least one finished job exists by listing jobs explicitly") By("Ensuring at least two jobs and at least one finished job exists by listing jobs explicitly")
err = waitForJobsAtLeast(f.Client, f.Namespace.Name, 2) err = waitForJobsAtLeast(c, ns, 2)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
err = waitForAnyFinishedJob(f.Client, f.Namespace.Name) err = waitForAnyFinishedJob(c, ns)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Ensuring no unexpected event has happened") By("Ensuring no unexpected event has happened")
err = checkNoUnexpectedEvents(f.Client, f.Namespace.Name, scheduledJob.Name) err = checkNoUnexpectedEvents(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
By("Removing scheduledjob") By("Removing scheduledjob")
err = deleteScheduledJob(f.Client, f.Namespace.Name, scheduledJob.Name) err = deleteScheduledJob(c, ns, scheduledJob.Name)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
}) })
}) })