1.kubectl copy /tmp/test-file test-pod:/
2.kubectl copy /tmp/test-file test-pod:
example 1 will fail, example 2 will cause a panic.
This patch fix bugs above.
A.support soft link better
before this patch
"kubectl cp" command will copy the soft link to destination as an empty regular file
after this patch
"kubectl cp" command will behave the same as tar command
this patch improves it on both from container and to container
B.fix some bugs
1.from container to host
a.when copy a file ends with '/', it will cause a panic.
for example, container gakki has a regular file /tmp/test, then run command
kubectl cp gakki:/tmp/test/ /tmp
panic happens
b.when copy a file which does not exist in container, the command ends up without
any error information
2.from host to container
a.when run command like
kubectl cp "" gakki:/tmp
it will try cp current directory to container, in other words, this command works
the same as kubectl cp . gakki:/tmp
b.current cp command will omit an empty directory
modified: pkg/kubectl/cmd/cp.go
modified: pkg/kubectl/cmd/cp_test.go
Automatic merge from submit-queue (batch tested with PRs 52109, 52235, 51809, 52161, 50080). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>..
Allow kubectl cp large amounts of files from container
When we try to copy out a dir with large amounts of files from container, we hit such error:
```bash
kubectl cp mypod:/ ./a/
tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
error: open a/usr/share/zoneinfo/Asia/Rangoon: too many open files
```
This is because kubectl opens too many files at the same. We should close them after Write() function.
**Release note**:
```
NONE
```
it happens when copy directory to pod and the directory
path ends with '/'.
for example:
kubectl cp /XX/XX/ XX-POD:/XX/XX
modified: pkg/kubectl/cmd/cp.go
modified: pkg/kubectl/cmd/cp_test.go
* Rename variables and functions to match Go convention.
For example, UsageError --> UsageErrorf.
* Remove redundant or unreachable code.
* Simplify some utility functions (no functionality changes).
* Fix hanging 'if { return } else { return }' constructs.
* Fix several incorrect printf verbs.