Commit Graph

19 Commits (13b12e89408869c5b560a81e95bca33267bdb8e1)

Author SHA1 Message Date
Kubernetes Submit Queue 2a04c09027
Merge pull request #58144 from tomerf/kubectl_cp_prefix
Automatic merge from submit-queue (batch tested with PRs 58144, 57149). 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>.

Fixed crash in kubectl cp when path has multiple leading slashes

**What this PR does / why we need it**: Fixed crash in kubectl cp when path has multiple leading slashes
For example:
```
$ kubectl cp pod://path/to/somewhere localfile
tar: Removing leading `//' from member names
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
k8s.io/kubernetes/pkg/kubectl/cmd.untarAll(0x363e840, 0xc420198120, 0x7fff5fbffc13, 0x1, 0x7fff5fbffbfa, 0x18, 0x0, 0x0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:329 +0x7b4
k8s.io/kubernetes/pkg/kubectl/cmd.copyFromPod(0x3671940, 0xc420261dd0, 0xc4202f9200, 0x3644480, 0xc42000c020, 0x0, 0x0, 0x7fff5fbffbed, 0xb, 0x7fff5fbffbf9, ...)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:237 +0x375
k8s.io/kubernetes/pkg/kubectl/cmd.runCopy(0x3671940, 0xc420261dd0, 0xc4202f9200, 0x3644480, 0xc42000c018, 0x3644480, 0xc42000c020, 0xc4203490a0, 0x2, 0x2, ...)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:134 +0x35b
k8s.io/kubernetes/pkg/kubectl/cmd.NewCmdCp.func1(0xc4202f9200, 0xc4203490a0, 0x2, 0x2)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:72 +0x89
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).execute(0xc4202f9200, 0xc420348ee0, 0x2, 0x2, 0xc4202f9200, 0xc420348ee0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:603 +0x234
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42038d440, 0x8000104, 0x0, 0xffffffffffffffff)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:689 +0x2fe
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42038d440, 0xc420261dd0, 0x3644440)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:648 +0x2b
k8s.io/kubernetes/cmd/kubectl/app.Run(0x0, 0x0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/cmd/kubectl/app/kubectl.go:41 +0xd5
main.main()
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/cmd/kubectl/kubectl.go:27 +0x26
```

**Which issue(s) this PR fixes** None

**Special notes for your reviewer**: None

**Release note**:
```release-note
Fixed crash in kubectl cp when path has multiple leading slashes
```
2018-01-22 19:02:27 -08:00
Tomer Froumin 52f02c42e6 Fixed crash when path has multiple leading slashes 2018-01-11 10:46:22 +02:00
Di Xu 1c715d51c4 some code change
fix wrong required flags

disable the addition of [flags] to the usage, use customized useline

fix function rename
2017-12-25 16:23:38 +08:00
Clayton Coleman d3790db03a
The cp command must call Close() on files, and does not pass on Mac
Path operations needed to be with filepath, not path (for cross
platform compat), and TMPDIR is not guaranteed to have a trailing slash.
2017-11-03 22:21:29 -04:00
WanLinghao b1f85e2dfe This patch improve kubectl cp command from two aspects
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
2017-10-13 13:51:53 +08:00
juanvallejo 2371accf0c
preserve specified destination path 2017-10-10 18:16:10 -04:00
bruceauyeung 19b572448a kubectl cp support coping remote file into local dir
Signed-off-by: bruceauyeung <ouyang.qinhua@zte.com.cn>
2017-09-28 10:06:07 +08:00
Kubernetes Submit Queue 90a4ac03dc Merge pull request #52161 from CaoShuFeng/kubectl_cp
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
```
2017-09-23 10:26:52 -07:00
WanLinghao c00f9bc140 fix kubectl cp command error.
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
2017-09-11 17:22:13 +08:00
Cao Shufeng 9820e65ed2 Allow kubectl cp large amounts of files from container 2017-09-08 18:42:23 +08:00
ymqytw b776df8a20 move i18n to kubectl/util 2017-08-16 12:27:36 -07:00
Alexander Campbell 6fd36c10ad kubectl/cmd: many small refactors
* 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.
2017-06-27 16:25:20 -07:00
Alexander Campbell ef9ae61240 kubectl: simplify code with help of linter 2017-06-23 09:49:30 -07:00
Alexander Campbell f9913c4948 kubectl: rewrite docstrings in several files
Fixing inaccuracies and clarifying in the case of ambiguities.
2017-06-23 09:49:30 -07:00
Kubernetes Submit Queue 19d722671b Merge pull request #43297 from mvdan/kubectl-params
Automatic merge from submit-queue

kubectl/cmd: remove a bunch of unused parameters

Found with github.com/mvdan/unparam.

**Release note**: NONE
2017-04-13 04:07:21 -07:00
Brendan Burns 79f51923d3 Extract a bunch more strings from kubectl 2017-04-06 20:12:50 -07:00
Daniel Martí 810dbc5e98 kubectl/cmd: remove a bunch of unused parameters
Found with github.com/mvdan/unparam.
2017-04-04 10:36:30 +01:00
Brendan Burns d9c4a289a6 Extract strings for translation. 2017-02-06 22:32:01 -08:00
Brendan Burns d65757fb88 add kubectl cp 2016-10-29 20:24:54 -07:00