Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
911e3e95
Commit
911e3e95
authored
Jun 02, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a bug in kubectl exec handling.
parent
3cb30e1e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
16 deletions
+34
-16
exec.go
pkg/kubectl/cmd/exec.go
+13
-11
exec_test.go
pkg/kubectl/cmd/exec_test.go
+21
-5
No files found.
pkg/kubectl/cmd/exec.go
View file @
911e3e95
...
@@ -80,27 +80,29 @@ type execParams struct {
...
@@ -80,27 +80,29 @@ type execParams struct {
tty
bool
tty
bool
}
}
func
extractPodAndContainer
(
cmd
*
cobra
.
Command
,
args
[]
string
,
p
*
execParams
)
(
podName
string
,
containerName
string
,
err
error
)
{
func
extractPodAndContainer
(
cmd
*
cobra
.
Command
,
args
In
[]
string
,
p
*
execParams
)
(
podName
string
,
containerName
string
,
args
[]
string
,
err
error
)
{
if
len
(
p
.
podName
)
==
0
&&
len
(
args
)
==
0
{
if
len
(
p
.
podName
)
==
0
&&
len
(
args
In
)
==
0
{
return
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"POD is required for exec"
)
return
""
,
""
,
nil
,
cmdutil
.
UsageError
(
cmd
,
"POD is required for exec"
)
}
}
if
len
(
p
.
podName
)
!=
0
{
if
len
(
p
.
podName
)
!=
0
{
printDeprecationWarning
(
"exec POD"
,
"-p POD"
)
printDeprecationWarning
(
"exec POD"
,
"-p POD"
)
podName
=
p
.
podName
podName
=
p
.
podName
if
len
(
args
)
<
1
{
if
len
(
args
In
)
<
1
{
return
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"COMMAND is required for exec"
)
return
""
,
""
,
nil
,
cmdutil
.
UsageError
(
cmd
,
"COMMAND is required for exec"
)
}
}
args
=
argsIn
}
else
{
}
else
{
podName
=
args
[
0
]
podName
=
argsIn
[
0
]
if
len
(
args
)
<
2
{
args
=
argsIn
[
1
:
]
return
""
,
""
,
cmdutil
.
UsageError
(
cmd
,
"COMMAND is required for exec"
)
if
len
(
args
)
<
1
{
return
""
,
""
,
nil
,
cmdutil
.
UsageError
(
cmd
,
"COMMAND is required for exec"
)
}
}
}
}
return
podName
,
p
.
containerName
,
nil
return
podName
,
p
.
containerName
,
args
,
nil
}
}
func
RunExec
(
f
*
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
cmdIn
io
.
Reader
,
cmdOut
,
cmdErr
io
.
Writer
,
p
*
execParams
,
args
[]
string
,
re
remoteExecutor
)
error
{
func
RunExec
(
f
*
cmdutil
.
Factory
,
cmd
*
cobra
.
Command
,
cmdIn
io
.
Reader
,
cmdOut
,
cmdErr
io
.
Writer
,
p
*
execParams
,
args
In
[]
string
,
re
remoteExecutor
)
error
{
podName
,
containerName
,
err
:=
extractPodAndContainer
(
cmd
,
args
,
p
)
podName
,
containerName
,
args
,
err
:=
extractPodAndContainer
(
cmd
,
argsIn
,
p
)
namespace
,
err
:=
f
.
DefaultNamespace
()
namespace
,
err
:=
f
.
DefaultNamespace
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/exec_test.go
View file @
911e3e95
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"reflect"
"testing"
"testing"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -43,58 +44,73 @@ func TestPodAndContainer(t *testing.T) {
...
@@ -43,58 +44,73 @@ func TestPodAndContainer(t *testing.T) {
tests
:=
[]
struct
{
tests
:=
[]
struct
{
args
[]
string
args
[]
string
p
*
execParams
p
*
execParams
name
string
expectError
bool
expectError
bool
expectedPod
string
expectedPod
string
expectedContainer
string
expectedContainer
string
expectedArgs
[]
string
}{
}{
{
{
p
:
&
execParams
{},
p
:
&
execParams
{},
expectError
:
true
,
expectError
:
true
,
name
:
"empty"
,
},
},
{
{
p
:
&
execParams
{
podName
:
"foo"
},
p
:
&
execParams
{
podName
:
"foo"
},
expectError
:
true
,
expectError
:
true
,
name
:
"no cmd"
,
},
},
{
{
p
:
&
execParams
{
podName
:
"foo"
,
containerName
:
"bar"
},
p
:
&
execParams
{
podName
:
"foo"
,
containerName
:
"bar"
},
expectError
:
true
,
expectError
:
true
,
name
:
"no cmd, w/ container"
,
},
},
{
{
p
:
&
execParams
{
podName
:
"foo"
},
p
:
&
execParams
{
podName
:
"foo"
},
args
:
[]
string
{
"cmd"
},
args
:
[]
string
{
"cmd"
},
expectedPod
:
"foo"
,
expectedPod
:
"foo"
,
expectedArgs
:
[]
string
{
"cmd"
},
name
:
"pod in flags"
,
},
},
{
{
p
:
&
execParams
{},
p
:
&
execParams
{},
args
:
[]
string
{
"foo"
},
args
:
[]
string
{
"foo"
},
expectError
:
true
,
expectError
:
true
,
name
:
"no cmd, w/o flags"
,
},
},
{
{
p
:
&
execParams
{},
p
:
&
execParams
{},
args
:
[]
string
{
"foo"
,
"cmd"
},
args
:
[]
string
{
"foo"
,
"cmd"
},
expectedPod
:
"foo"
,
expectedPod
:
"foo"
,
expectedArgs
:
[]
string
{
"cmd"
},
name
:
"cmd, w/o flags"
,
},
},
{
{
p
:
&
execParams
{
containerName
:
"bar"
},
p
:
&
execParams
{
containerName
:
"bar"
},
args
:
[]
string
{
"foo"
,
"cmd"
},
args
:
[]
string
{
"foo"
,
"cmd"
},
expectedPod
:
"foo"
,
expectedPod
:
"foo"
,
expectedContainer
:
"bar"
,
expectedContainer
:
"bar"
,
expectedArgs
:
[]
string
{
"cmd"
},
name
:
"cmd, container in flag"
,
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
cmd
:=
&
cobra
.
Command
{}
cmd
:=
&
cobra
.
Command
{}
podName
,
containerName
,
err
:=
extractPodAndContainer
(
cmd
,
test
.
args
,
test
.
p
)
podName
,
containerName
,
args
,
err
:=
extractPodAndContainer
(
cmd
,
test
.
args
,
test
.
p
)
if
podName
!=
test
.
expectedPod
{
if
podName
!=
test
.
expectedPod
{
t
.
Errorf
(
"expected: %s, got: %s
"
,
test
.
expectedPod
,
podN
ame
)
t
.
Errorf
(
"expected: %s, got: %s
(%s)"
,
test
.
expectedPod
,
podName
,
test
.
n
ame
)
}
}
if
containerName
!=
test
.
expectedContainer
{
if
containerName
!=
test
.
expectedContainer
{
t
.
Errorf
(
"expected: %s, got: %s
"
,
test
.
expectedContainer
,
containerN
ame
)
t
.
Errorf
(
"expected: %s, got: %s
(%s)"
,
test
.
expectedContainer
,
containerName
,
test
.
n
ame
)
}
}
if
test
.
expectError
&&
err
==
nil
{
if
test
.
expectError
&&
err
==
nil
{
t
.
Error
(
"unexpected non-error"
)
t
.
Error
f
(
"unexpected non-error (%s)"
,
test
.
name
)
}
}
if
!
test
.
expectError
&&
err
!=
nil
{
if
!
test
.
expectError
&&
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v (%s)"
,
err
,
test
.
name
)
}
if
!
reflect
.
DeepEqual
(
test
.
expectedArgs
,
args
)
{
t
.
Errorf
(
"expected: %v, got %v (%s)"
,
test
.
expectedArgs
,
args
,
test
.
name
)
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment