kubectl run --restart=Never creates pods

This commit is contained in:
Maciej Szulik
2016-05-06 11:39:44 +02:00
parent b61ce0bc81
commit d76fa8a119
5 changed files with 46 additions and 29 deletions

View File

@@ -354,7 +354,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
nsFlag := fmt.Sprintf("--namespace=%v", ns)
By("executing a command with run and attach with stdin")
runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=Never", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
runOutput := framework.NewKubectlCommand(nsFlag, "run", "run-test", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
WithStdinData("abcd1234").
ExecOrDie()
Expect(runOutput).To(ContainSubstring("abcd1234"))
@@ -362,7 +362,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
Expect(c.Extensions().Jobs(ns).Delete("run-test", nil)).To(BeNil())
By("executing a command with run and attach without stdin")
runOutput = framework.NewKubectlCommand(fmt.Sprintf("--namespace=%v", ns), "run", "run-test-2", "--image="+busyboxImage, "--restart=Never", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "cat && echo 'stdin closed'").
runOutput = framework.NewKubectlCommand(fmt.Sprintf("--namespace=%v", ns), "run", "run-test-2", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--", "sh", "-c", "cat && echo 'stdin closed'").
WithStdinData("abcd1234").
ExecOrDie()
Expect(runOutput).ToNot(ContainSubstring("abcd1234"))
@@ -370,7 +370,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
Expect(c.Extensions().Jobs(ns).Delete("run-test-2", nil)).To(BeNil())
By("executing a command with run and attach with stdin with open stdin should remain running")
runOutput = framework.NewKubectlCommand(nsFlag, "run", "run-test-3", "--image="+busyboxImage, "--restart=Never", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
runOutput = framework.NewKubectlCommand(nsFlag, "run", "run-test-3", "--image="+busyboxImage, "--restart=OnFailure", "--attach=true", "--leave-stdin-open=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
WithStdinData("abcd1234\n").
ExecOrDie()
Expect(runOutput).ToNot(ContainSubstring("stdin closed"))
@@ -992,7 +992,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
framework.SkipUnlessServerVersionGTE(jobsVersion, c)
By("running the image " + nginxImage)
framework.RunKubectlOrDie("run", jobName, "--restart=OnFailure", "--image="+nginxImage, nsFlag)
framework.RunKubectlOrDie("run", jobName, "--restart=OnFailure", "--generator=job/v1", "--image="+nginxImage, nsFlag)
By("verifying the job " + jobName + " was created")
job, err := c.Extensions().Jobs(ns).Get(jobName)
if err != nil {
@@ -1006,23 +1006,37 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
framework.Failf("Failed creating a job with correct restart policy for --restart=OnFailure")
}
})
})
It("should create a job from an image when restart is Never [Conformance]", func() {
framework.KubeDescribe("Kubectl run pod", func() {
var nsFlag string
var podName string
BeforeEach(func() {
nsFlag = fmt.Sprintf("--namespace=%v", ns)
podName = "e2e-test-nginx-pod"
})
AfterEach(func() {
framework.RunKubectlOrDie("delete", "pods", podName, nsFlag)
})
It("should create a pod from an image when restart is Never [Conformance]", func() {
framework.SkipUnlessServerVersionGTE(jobsVersion, c)
By("running the image " + nginxImage)
framework.RunKubectlOrDie("run", jobName, "--restart=Never", "--image="+nginxImage, nsFlag)
By("verifying the job " + jobName + " was created")
job, err := c.Extensions().Jobs(ns).Get(jobName)
framework.RunKubectlOrDie("run", podName, "--restart=Never", "--generator=run-pod/v1", "--image="+nginxImage, nsFlag)
By("verifying the pod " + podName + " was created")
pod, err := c.Pods(ns).Get(podName)
if err != nil {
framework.Failf("Failed getting job %s: %v", jobName, err)
framework.Failf("Failed getting pod %s: %v", podName, err)
}
containers := job.Spec.Template.Spec.Containers
containers := pod.Spec.Containers
if containers == nil || len(containers) != 1 || containers[0].Image != nginxImage {
framework.Failf("Failed creating job %s for 1 pod with expected image %s", jobName, nginxImage)
framework.Failf("Failed creating pod %s with expected image %s", podName, nginxImage)
}
if job.Spec.Template.Spec.RestartPolicy != api.RestartPolicyNever {
framework.Failf("Failed creating a job with correct restart policy for --restart=OnFailure")
if pod.Spec.RestartPolicy != api.RestartPolicyNever {
framework.Failf("Failed creating a pod with correct restart policy for --restart=Never")
}
})
})
@@ -1037,7 +1051,7 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
By("executing a command with run --rm and attach with stdin")
t := time.NewTimer(runJobTimeout)
defer t.Stop()
runOutput := framework.NewKubectlCommand(nsFlag, "run", jobName, "--image="+busyboxImage, "--rm=true", "--restart=Never", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
runOutput := framework.NewKubectlCommand(nsFlag, "run", jobName, "--image="+busyboxImage, "--rm=true", "--generator=job/v1", "--restart=OnFailure", "--attach=true", "--stdin", "--", "sh", "-c", "cat && echo 'stdin closed'").
WithStdinData("abcd1234").
WithTimeout(t.C).
ExecOrDie()