mirror of
https://github.com/kubernetes/kubectl.git
synced 2026-06-07 15:52:44 -04:00
Merge pull request #90333 from bamarni/kubectl-cp-unexisting-file
[kubectl] Fail when local source file doesn't exist Kubernetes-commit: 1485d462efcfc27047790639543d2cc515a27d7a
This commit is contained in:
commit
f3e568c411
5 changed files with 26 additions and 17 deletions
6
Godeps/Godeps.json
generated
6
Godeps/Godeps.json
generated
|
|
@ -916,7 +916,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "01c5338f427f"
|
||||
"Rev": "3e589e9d21e6"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
|
|
@ -928,7 +928,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/client-go",
|
||||
"Rev": "1eb2027cd51e"
|
||||
"Rev": "9950c71bb5a3"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/code-generator",
|
||||
|
|
@ -936,7 +936,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/component-base",
|
||||
"Rev": "31183c05d879"
|
||||
"Rev": "cb2bdd362651"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/component-helpers",
|
||||
|
|
|
|||
12
go.mod
12
go.mod
|
|
@ -34,11 +34,11 @@ require (
|
|||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
k8s.io/api v0.0.0-20201104162213-01c5338f427f
|
||||
k8s.io/api v0.0.0-20201106042650-3e589e9d21e6
|
||||
k8s.io/apimachinery v0.0.0-20201105042036-d67967d70958
|
||||
k8s.io/cli-runtime v0.0.0-20201105205002-d004bfbce7ab
|
||||
k8s.io/client-go v0.0.0-20201105042428-1eb2027cd51e
|
||||
k8s.io/component-base v0.0.0-20201105203028-31183c05d879
|
||||
k8s.io/client-go v0.0.0-20201106002952-9950c71bb5a3
|
||||
k8s.io/component-base v0.0.0-20201106122545-cb2bdd362651
|
||||
k8s.io/component-helpers v0.0.0-20201104163002-2a464068d690
|
||||
k8s.io/klog/v2 v2.4.0
|
||||
k8s.io/kube-openapi v0.0.0-20200923155610-8b5066479488
|
||||
|
|
@ -49,12 +49,12 @@ require (
|
|||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20201104162213-01c5338f427f
|
||||
k8s.io/api => k8s.io/api v0.0.0-20201106042650-3e589e9d21e6
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20201105042036-d67967d70958
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20201105205002-d004bfbce7ab
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20201105042428-1eb2027cd51e
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20201106002952-9950c71bb5a3
|
||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20201104161901-3609764c976f
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20201105203028-31183c05d879
|
||||
k8s.io/component-base => k8s.io/component-base v0.0.0-20201106122545-cb2bdd362651
|
||||
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20201104163002-2a464068d690
|
||||
k8s.io/metrics => k8s.io/metrics v0.0.0-20201104164049-295e9ef2a627
|
||||
)
|
||||
|
|
|
|||
6
go.sum
6
go.sum
|
|
@ -558,12 +558,12 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
k8s.io/api v0.0.0-20201104162213-01c5338f427f/go.mod h1:5iJ2LFNvkNfwL+E+lMewJWlnnT3Fpj1BYHa2Qb4fjrI=
|
||||
k8s.io/api v0.0.0-20201106042650-3e589e9d21e6/go.mod h1:zAGvr1xjhxenCwQv5PukMiA1OeGGbA56Wn+D2Fgkiqw=
|
||||
k8s.io/apimachinery v0.0.0-20201105042036-d67967d70958/go.mod h1:WC5jfah6jg0OD6SE11oSOCQHkfkLh7pwIYbwS/dZLe4=
|
||||
k8s.io/cli-runtime v0.0.0-20201105205002-d004bfbce7ab/go.mod h1:WncQPvHb8X7yBCgkLPxfDx3CsUdvaCa2CToQQiuvDpU=
|
||||
k8s.io/client-go v0.0.0-20201105042428-1eb2027cd51e/go.mod h1:Uk/f7lE00tI0bzmlKkW6JIIYZkqd8dFonXGaHo46ya0=
|
||||
k8s.io/client-go v0.0.0-20201106002952-9950c71bb5a3/go.mod h1:Uk/f7lE00tI0bzmlKkW6JIIYZkqd8dFonXGaHo46ya0=
|
||||
k8s.io/code-generator v0.0.0-20201104161901-3609764c976f/go.mod h1:XBVD9f8PJVt5zdhi95/mi/yGQEn1GSqbrfD17zGD/l4=
|
||||
k8s.io/component-base v0.0.0-20201105203028-31183c05d879/go.mod h1:IrWoY0Tqt1Tp0TBNzk0tW1X/+G+GDgMuwQvYgSIIoqA=
|
||||
k8s.io/component-base v0.0.0-20201106122545-cb2bdd362651/go.mod h1:UukorDQSQHga2nX5SOhmk6jenqOcWfkTz13zfV03N/s=
|
||||
k8s.io/component-helpers v0.0.0-20201104163002-2a464068d690/go.mod h1:FMntmyDIm1iLTi5gEQ5hKfovf7cGLvAKBX/66698Z4Q=
|
||||
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
|
|
|
|||
|
|
@ -203,10 +203,7 @@ func (o *CopyOptions) Run(args []string) error {
|
|||
}
|
||||
|
||||
if len(srcSpec.PodName) != 0 && len(destSpec.PodName) != 0 {
|
||||
if _, err := os.Stat(args[0]); err == nil {
|
||||
return o.copyToPod(fileSpec{File: args[0]}, destSpec, &exec.ExecOptions{})
|
||||
}
|
||||
return fmt.Errorf("src doesn't exist in local filesystem")
|
||||
return fmt.Errorf("one of src or dest must be a local file specification")
|
||||
}
|
||||
|
||||
if len(srcSpec.PodName) != 0 {
|
||||
|
|
@ -245,6 +242,9 @@ func (o *CopyOptions) copyToPod(src, dest fileSpec, options *exec.ExecOptions) e
|
|||
if len(src.File) == 0 || len(dest.File) == 0 {
|
||||
return errFileCannotBeEmpty
|
||||
}
|
||||
if _, err := os.Stat(src.File); err != nil {
|
||||
return fmt.Errorf("%s doesn't exist in local filesystem", src.File)
|
||||
}
|
||||
reader, writer := io.Pipe()
|
||||
|
||||
// strip trailing slash (if any)
|
||||
|
|
|
|||
|
|
@ -576,27 +576,36 @@ func TestCopyToPod(t *testing.T) {
|
|||
defer os.RemoveAll(srcFile)
|
||||
|
||||
tests := map[string]struct {
|
||||
src string
|
||||
dest string
|
||||
expectedErr bool
|
||||
}{
|
||||
"copy to directory": {
|
||||
src: srcFile,
|
||||
dest: "/tmp/",
|
||||
expectedErr: false,
|
||||
},
|
||||
"copy to root": {
|
||||
src: srcFile,
|
||||
dest: "/",
|
||||
expectedErr: false,
|
||||
},
|
||||
"copy to empty file name": {
|
||||
src: srcFile,
|
||||
dest: "",
|
||||
expectedErr: true,
|
||||
},
|
||||
"copy unexisting file": {
|
||||
src: path.Join(srcFile, "nope"),
|
||||
dest: "/tmp",
|
||||
expectedErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, test := range tests {
|
||||
opts := NewCopyOptions(ioStreams)
|
||||
src := fileSpec{
|
||||
File: srcFile,
|
||||
File: test.src,
|
||||
}
|
||||
dest := fileSpec{
|
||||
PodNamespace: "pod-ns",
|
||||
|
|
|
|||
Loading…
Reference in a new issue