You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: staging/src/k8s.io/kubectl/pkg/cmd/exec/exec.go
+29-18Lines changed: 29 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -45,10 +45,10 @@ import (
45
45
var (
46
46
execExample=templates.Examples(i18n.T(`
47
47
# Get output from running 'date' command from pod mypod, using the first container by default
48
-
kubectl exec mypod date
48
+
kubectl exec mypod -- date
49
49
50
50
# Get output from running 'date' command in ruby-container from pod mypod
51
-
kubectl exec mypod -c ruby-container date
51
+
kubectl exec mypod -c ruby-container -- date
52
52
53
53
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
54
54
# and sends stdout/stderr from 'bash' back to the client
@@ -62,15 +62,14 @@ var (
62
62
kubectl exec mypod -i -t -- ls -t /usr
63
63
64
64
# Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
65
-
kubectl exec deploy/mydeployment date
65
+
kubectl exec deploy/mydeployment -- date
66
66
67
67
# Get output from running 'date' command from the first pod of the service myservice, using the first container by default
68
-
kubectl exec svc/myservice date
68
+
kubectl exec svc/myservice -- date
69
69
`))
70
70
)
71
71
72
72
const (
73
-
execUsageStr="expected 'exec (POD | TYPE/NAME) COMMAND [ARG1] [ARG2] ... [ARGN]'.\nPOD or TYPE/NAME and COMMAND are required arguments for the exec command"
cmdutil.AddJsonFilenameFlag(cmd.Flags(), &options.FilenameOptions.Filenames, "to use to exec into the resource")
99
99
// TODO support UID
100
100
cmd.Flags().StringVarP(&options.ContainerName, "container", "c", options.ContainerName, "Container name. If omitted, the first container in the pod will be chosen")
101
101
cmd.Flags().BoolVarP(&options.Stdin, "stdin", "i", options.Stdin, "Pass stdin to the container")
@@ -146,9 +146,11 @@ type StreamOptions struct {
146
146
// ExecOptions declare the arguments accepted by the Exec command
147
147
typeExecOptionsstruct {
148
148
StreamOptions
149
+
resource.FilenameOptions
149
150
150
-
ResourceNamestring
151
-
Command []string
151
+
ResourceNamestring
152
+
Command []string
153
+
EnforceNamespacebool
152
154
153
155
ParentCommandNamestring
154
156
EnableSuggestedCmdUsagebool
@@ -166,17 +168,22 @@ type ExecOptions struct {
166
168
167
169
// Complete verifies command line arguments and loads data from the command environment
// Let kubectl exec follow rules for `--`, see #13004 issue
170
-
iflen(argsIn) ==0||argsLenAtDash==0 {
171
-
returncmdutil.UsageErrorf(cmd, execUsageStr)
171
+
iflen(argsIn) >0&&argsLenAtDash!=0 {
172
+
p.ResourceName=argsIn[0]
173
+
}
174
+
ifargsLenAtDash>-1 {
175
+
p.Command=argsIn[argsLenAtDash:]
176
+
} elseiflen(argsIn) >1 {
177
+
fmt.Fprint(p.ErrOut, "kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.\n")
fmt.Fprint(p.ErrOut, "kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.\n")
0 commit comments