kubernetes: kubectl cp does not return an error when the source file doesn't exist
What happened:
Running kubectl cp /some/file/that/doesnt/exist pod:/tmp
silently fails if that source file doesn’t exist.
What you expected to happen:
I expected kubectl to exit with a non-zero status code and to print a standard error message like so:
ls: /some/file/that/doesnt/exist: No such file or directory
How to reproduce it (as minimally and precisely as possible):
Find any running pod, try to copy a non-existent file:
pod=$(kubectl get pod -o jsonpath='{ .items[0].metadata.name }')
kubectl cp /some/file/that/doesnt/exist $pod:/tmp
echo $? # echos 0 when it should echo 1
Anything else we need to know?:
kubectl cp existing-file $pod:/some/dir/that/doesnt/exist
works right. For example:
$ ls -l xyz
-rw-r--r-- 1 dpk staff 1663 Jun 10 17:26 xyz
$ kubectl cp xyz $pod:/some/dir/that/doesnt/exist
tar: /some/dir/that/doesnt: Cannot open: No such file or directory
$ echo $?
2
I’m sure this has something to do with the fact that kubectl
uses tar
under the hood. However, tar
itself will report an error if you try to extract a file that doesn’t exist, so maybe this is just a matter of not including the to-be-extracted-path(s) on the end of the tar command line.
This might be fixed by appending src.File
(or rather the basename of it) to the end of the array here: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/cmd/cp/cp.go#L251 (haven’t tried it).
Environment:
- Kubernetes version (use
kubectl version
):
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
and
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.6-gke.0", GitCommit:"14c9138d6fb5b57473e270fe8a2973300fbd6fd6", GitTreeState:"clean", BuildDate:"2019-05-08T16:22:55Z", GoVersion:"go1.11.5b4", Compiler:"gc", Platform:"linux/amd64"}
- Cloud provider or hardware configuration: docker-for-desktop 2.0.4.1 (34207) and GKE running 1.13.6-gke-0
- OS (e.g:
cat /etc/os-release
): macOS 10.14.5 - Kernel (e.g.
uname -a
):Darwin nacho.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
- Install tools: Installed docker from dmg, using the included
kubectl
- Network plugin and version (if this is a network-related bug):
- Others:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 14
- Comments: 26 (13 by maintainers)
For me
kubectl cp
never copies anything and never writes any info to console. Even if I point it to non-existing pod, it just exists with no trace.