mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +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:
@@ -56,7 +56,7 @@ kubectl run nginx --image=nginx --dry-run
|
||||
# Start a single instance of nginx, but overload the spec of the deployment with a partial set of values parsed from JSON.
|
||||
kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
|
||||
|
||||
# Start a single instance of busybox and keep it in the foreground, don't restart it if it exits.
|
||||
# Start a pod of busybox and keep it in the foreground, don't restart it if it exits.
|
||||
kubectl run -i -t busybox --image=busybox --restart=Never
|
||||
|
||||
# Start the nginx container using the default command, but use custom arguments (arg1 .. argN) for that command.
|
||||
@@ -93,7 +93,7 @@ func NewCmdRun(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer) *c
|
||||
|
||||
func addRunFlags(cmd *cobra.Command) {
|
||||
cmdutil.AddDryRunFlag(cmd)
|
||||
cmd.Flags().String("generator", "", "The name of the API generator to use. Default is 'deployment/v1beta1' if --restart=Always, otherwise the default is 'job/v1'. This will happen only for cluster version at least 1.2, for olders we will fallback to 'run/v1' for --restart=Always, 'run-pod/v1' for others.")
|
||||
cmd.Flags().String("generator", "", "The name of the API generator to use. Default is 'deployment/v1beta1' if --restart=Always, 'job/v1' for OnFailure and 'run-pod/v1' for Never. This will happen only for cluster version at least 1.3, for 1.2 we will fallback to 'deployment/v1beta1' for --restart=Always, 'job/v1' for others, for olders we will fallback to 'run/v1' for --restart=Always, 'run-pod/v1' for others.")
|
||||
cmd.Flags().String("image", "", "The image for the container to run.")
|
||||
cmd.MarkFlagRequired("image")
|
||||
cmd.Flags().IntP("replicas", "r", 1, "Number of replicas to create for this container. Default is 1.")
|
||||
@@ -107,7 +107,7 @@ func addRunFlags(cmd *cobra.Command) {
|
||||
cmd.Flags().BoolP("tty", "t", false, "Allocated a TTY for each container in the pod.")
|
||||
cmd.Flags().Bool("attach", false, "If true, wait for the Pod to start running, and then attach to the Pod as if 'kubectl attach ...' were called. Default false, unless '-i/--interactive' is set, in which case the default is true.")
|
||||
cmd.Flags().Bool("leave-stdin-open", false, "If the pod is started in interactive mode or with stdin, leave stdin open after the first attach completes. By default, stdin will be closed after the first attach completes.")
|
||||
cmd.Flags().String("restart", "Always", "The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to 'Always' a deployment is created for this pod, if set to OnFailure or Never, a job is created for this pod and --replicas must be 1. Default 'Always'")
|
||||
cmd.Flags().String("restart", "Always", "The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to 'Always' a deployment is created for this pod, if set to 'OnFailure', a job is created for this pod, if set to 'Never', a regular pod is created. For the latter two --replicas must be 1. Default 'Always'")
|
||||
cmd.Flags().Bool("command", false, "If true and extra arguments are present, use them as the 'command' field in the container, rather than the 'args' field which is the default.")
|
||||
cmd.Flags().String("requests", "", "The resource requirement requests for this container. For example, 'cpu=100m,memory=256Mi'. Note that server side components may assign requests depending on the server configuration, such as limit ranges.")
|
||||
cmd.Flags().String("limits", "", "The resource requirement limits for this container. For example, 'cpu=200m,memory=512Mi'. Note that server side components may assign limits depending on the server configuration, such as limit ranges.")
|
||||
@@ -159,13 +159,14 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
|
||||
// this cover the cases where old servers do not expose discovery
|
||||
resourcesList = nil
|
||||
}
|
||||
if restartPolicy == api.RestartPolicyAlways {
|
||||
switch restartPolicy {
|
||||
case api.RestartPolicyAlways:
|
||||
if contains(resourcesList, v1beta1.SchemeGroupVersion.WithResource("deployments")) {
|
||||
generatorName = "deployment/v1beta1"
|
||||
} else {
|
||||
generatorName = "run/v1"
|
||||
}
|
||||
} else {
|
||||
case api.RestartPolicyOnFailure:
|
||||
if contains(resourcesList, batchv1.SchemeGroupVersion.WithResource("jobs")) {
|
||||
generatorName = "job/v1"
|
||||
} else if contains(resourcesList, v1beta1.SchemeGroupVersion.WithResource("jobs")) {
|
||||
@@ -173,6 +174,8 @@ func Run(f *cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *cob
|
||||
} else {
|
||||
generatorName = "run-pod/v1"
|
||||
}
|
||||
case api.RestartPolicyNever:
|
||||
generatorName = "run-pod/v1"
|
||||
}
|
||||
}
|
||||
generators := f.Generators("run")
|
||||
|
||||
Reference in New Issue
Block a user