mirror of https://github.com/k3s-io/k3s
Add Jobs to k8s upgrade tests
parent
e3840da83d
commit
a4f614f2db
|
@ -52,6 +52,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
|
||||||
testConfigMapsDuringUpgrade(f, sem)
|
testConfigMapsDuringUpgrade(f, sem)
|
||||||
testGuestbookApplicationDuringUpgrade(f, sem)
|
testGuestbookApplicationDuringUpgrade(f, sem)
|
||||||
testDaemonSetDuringUpgrade(f, sem)
|
testDaemonSetDuringUpgrade(f, sem)
|
||||||
|
testJobsDuringUpgrade(f, sem)
|
||||||
})
|
})
|
||||||
cm.Do()
|
cm.Do()
|
||||||
})
|
})
|
||||||
|
@ -72,6 +73,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
|
||||||
testConfigMapsBeforeAndAfterUpgrade(f, sem)
|
testConfigMapsBeforeAndAfterUpgrade(f, sem)
|
||||||
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
|
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
|
||||||
testDaemonSetBeforeAndAfterUpgrade(f, sem)
|
testDaemonSetBeforeAndAfterUpgrade(f, sem)
|
||||||
|
testJobsBeforeAndAfterUpgrade(f, sem)
|
||||||
})
|
})
|
||||||
cm.Do()
|
cm.Do()
|
||||||
})
|
})
|
||||||
|
@ -90,6 +92,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
|
||||||
testConfigMapsDuringUpgrade(f, sem)
|
testConfigMapsDuringUpgrade(f, sem)
|
||||||
testGuestbookApplicationDuringUpgrade(f, sem)
|
testGuestbookApplicationDuringUpgrade(f, sem)
|
||||||
testDaemonSetDuringUpgrade(f, sem)
|
testDaemonSetDuringUpgrade(f, sem)
|
||||||
|
testJobsDuringUpgrade(f, sem)
|
||||||
})
|
})
|
||||||
cm.Do()
|
cm.Do()
|
||||||
})
|
})
|
||||||
|
@ -112,6 +115,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
|
||||||
testConfigMapsBeforeAndAfterUpgrade(f, sem)
|
testConfigMapsBeforeAndAfterUpgrade(f, sem)
|
||||||
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
|
testGuestbookApplicationBeforeAndAfterUpgrade(f, sem)
|
||||||
testDaemonSetBeforeAndAfterUpgrade(f, sem)
|
testDaemonSetBeforeAndAfterUpgrade(f, sem)
|
||||||
|
testJobsBeforeAndAfterUpgrade(f, sem)
|
||||||
})
|
})
|
||||||
cm.Do()
|
cm.Do()
|
||||||
})
|
})
|
||||||
|
@ -132,6 +136,7 @@ var _ = framework.KubeDescribe("Upgrade [Feature:Upgrade]", func() {
|
||||||
testConfigMapsDuringUpgrade(f, sem)
|
testConfigMapsDuringUpgrade(f, sem)
|
||||||
testGuestbookApplicationDuringUpgrade(f, sem)
|
testGuestbookApplicationDuringUpgrade(f, sem)
|
||||||
testDaemonSetDuringUpgrade(f, sem)
|
testDaemonSetDuringUpgrade(f, sem)
|
||||||
|
testJobsDuringUpgrade(f, sem)
|
||||||
})
|
})
|
||||||
cm.Do()
|
cm.Do()
|
||||||
})
|
})
|
||||||
|
@ -404,3 +409,43 @@ func testDaemonSet(f *framework.Framework, sem *chaosmonkey.Semaphore, testDurin
|
||||||
By("teardown daemonset")
|
By("teardown daemonset")
|
||||||
TestDaemonSetWithNodeAffinityTeardown(f, dsName)
|
TestDaemonSetWithNodeAffinityTeardown(f, dsName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testJobsBeforeAndAfterUpgrade(f *framework.Framework, sem *chaosmonkey.Semaphore) {
|
||||||
|
testJobs(f, sem, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJobsDuringUpgrade(f *framework.Framework, sem *chaosmonkey.Semaphore) {
|
||||||
|
testJobs(f, sem, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testJobs(f *framework.Framework, sem *chaosmonkey.Semaphore, testDuringDisruption bool) {
|
||||||
|
parallelism := int32(2)
|
||||||
|
completions := int32(4)
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
By("setup job")
|
||||||
|
job := TestJobsSetup("randomlySucceedOrFail", "rand-non-local", api.RestartPolicyNever, parallelism, completions)
|
||||||
|
// Validate
|
||||||
|
By("validate job before upgrade")
|
||||||
|
TestJobsValidate(f, job, completions)
|
||||||
|
|
||||||
|
sem.Ready()
|
||||||
|
|
||||||
|
if testDuringDisruption {
|
||||||
|
// Continuously validate
|
||||||
|
wait.Until(func() {
|
||||||
|
By("validate job during upgrade")
|
||||||
|
TestJobsValidate(f, job, completions)
|
||||||
|
}, framework.Poll, sem.StopCh)
|
||||||
|
} else {
|
||||||
|
// Block until chaosmonkey is done
|
||||||
|
By("waiting for upgrade to finish without validating job")
|
||||||
|
<-sem.StopCh
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate after upgrade
|
||||||
|
By("validate job after upgrade")
|
||||||
|
TestJobsValidate(f, job, completions)
|
||||||
|
|
||||||
|
// Teardown
|
||||||
|
}
|
||||||
|
|
|
@ -79,20 +79,13 @@ var _ = framework.KubeDescribe("Job", func() {
|
||||||
|
|
||||||
// Pods sometimes fail, but eventually succeed, after pod restarts
|
// Pods sometimes fail, but eventually succeed, after pod restarts
|
||||||
It("should run a job to completion when tasks sometimes fail and are not locally restarted", func() {
|
It("should run a job to completion when tasks sometimes fail and are not locally restarted", func() {
|
||||||
By("Creating a job")
|
|
||||||
// 50% chance of container success, local restarts.
|
// 50% chance of container success, local restarts.
|
||||||
// Can't use the failOnce approach because that relies
|
// Can't use the failOnce approach because that relies
|
||||||
// on an emptyDir, which is not preserved across new pods.
|
// on an emptyDir, which is not preserved across new pods.
|
||||||
// Worst case analysis: 15 failures, each taking 1 minute to
|
// Worst case analysis: 15 failures, each taking 1 minute to
|
||||||
// run due to some slowness, 1 in 2^15 chance of happening,
|
// run due to some slowness, 1 in 2^15 chance of happening,
|
||||||
// causing test flake. Should be very rare.
|
// causing test flake. Should be very rare.
|
||||||
job := newTestJob("randomlySucceedOrFail", "rand-non-local", api.RestartPolicyNever, parallelism, completions)
|
TestJobs(f, "randomlySucceedOrFail", "rand-non-local", api.RestartPolicyNever, parallelism, completions)
|
||||||
job, err := createJob(f.ClientSet, f.Namespace.Name, job)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
|
|
||||||
By("Ensuring job reaches completions")
|
|
||||||
err = waitForJobFinish(f.ClientSet, f.Namespace.Name, job.Name, completions)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
})
|
})
|
||||||
|
|
||||||
It("should keep restarting failed pods", func() {
|
It("should keep restarting failed pods", func() {
|
||||||
|
@ -339,3 +332,26 @@ func newBool(val bool) *bool {
|
||||||
*p = val
|
*p = val
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestJobsSetup(behavior, name string, rPol api.RestartPolicy, parallelism, completions int32) *batch.Job {
|
||||||
|
return newTestJob(behavior, name, rPol, parallelism, completions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJobsValidate(f *framework.Framework, job *batch.Job, completions int32) {
|
||||||
|
By("Creating a job")
|
||||||
|
job, err := createJob(f.ClientSet, f.Namespace.Name, job)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("Ensuring job reaches completions")
|
||||||
|
err = waitForJobFinish(f.ClientSet, f.Namespace.Name, job.Name, completions)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("Delete the job")
|
||||||
|
err = deleteJob(f.ClientSet, f.Namespace.Name, job.ObjectMeta.Name)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJobs(f *framework.Framework, behavior, name string, rPol api.RestartPolicy, parallelism, completions int32) {
|
||||||
|
job := TestJobsSetup(behavior, name, rPol, parallelism, completions)
|
||||||
|
TestJobsValidate(f, job, completions)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue