mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-27 13:15:36 +00:00
Merge pull request #25253 from soltysh/issue24533
Automatic merge from submit-queue kubectl run --restart=Never creates pods Fixes #24533. @bgrant0607 @janetkuo ptal /fyi @thockin ```release-note * kubectl run --restart=Never creates pods ``` []()
This commit is contained in:
@@ -353,7 +353,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"))
|
||||
@@ -361,7 +361,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"))
|
||||
@@ -369,7 +369,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"))
|
||||
@@ -990,7 +990,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 {
|
||||
@@ -1004,23 +1004,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")
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1035,7 +1049,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()
|
||||
|
Reference in New Issue
Block a user