Merge pull request #51595 from WanLinghao/kubectl_cp_error

Automatic merge from submit-queue (batch tested with PRs 51438, 52182, 51607, 47912, 51595). 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>..

fix kubectl cp command error

fix kubectl cp command error.

modified:   pkg/kubectl/cmd/cp.go



**What this PR does / why we need it**:
fix kubectl cp error.
it happens when copy directory to pod and the directory path ends with '/'.
for example:
kubectl cp /tmp/test/ test-pod:/tmp/test/
it will fail with 
error: stat /tmp/test/test: no such file or directory

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes 

**Special notes for your reviewer**:

**Release note**:

```release-note
```
pull/6/head
Kubernetes Submit Queue 2017-09-23 08:09:54 -07:00 committed by GitHub
commit d042a1d7d1
2 changed files with 3 additions and 0 deletions

View File

@ -195,6 +195,8 @@ func makeTar(filepath string, writer io.Writer) error {
// TODO: use compression here?
tarWriter := tar.NewWriter(writer)
defer tarWriter.Close()
filepath = path.Clean(filepath)
return recursiveTar(path.Dir(filepath), path.Base(filepath), tarWriter)
}

View File

@ -104,6 +104,7 @@ func TestTarUntar(t *testing.T) {
t.Errorf("unexpected error: %v | %v", err, err2)
t.FailNow()
}
dir = dir + "/"
defer func() {
if err := os.RemoveAll(dir); err != nil {
t.Errorf("Unexpected error cleaning up: %v", err)