Change:
<!-- This form is for bug reports and feature requests ONLY! If you're looking for help check and the . If the matter is security related, please disclose it privately via --Is this a BUG REPORT or FEATURE REQUEST?: What happened: panics What you expected to happen: Syntax error, as it is not legit cp syntax. How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Occurs in every version 1.9.x and 1.10.x, but 1.8.x is safe. is similar, but it has a fix candidate already going in, that is not fixing this, so opening a separate issue. Environment: Kubernetes version (use ):Cloud provider or hardware configuration: VM OS (e.g. from /etc/os-release): Ubuntu 18.04 Kernel (e.g. ): /sig cli
It seems to be fixed in 1.11 by
It was merged three months ago, any idea why it isn't in 1.10 too?
It was merged on March 31 and 1.10 was released on March 27: Can confirm it is not present in 1.10: Maybe we can cherry-pick it?
I've opened
Fixed by /close
Closing this issue. <detailsIn response to : Fixed by Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details

Discussion:
} func copyToPod(f cmdutil.Factory, cmd *cobra.Command, stdout, stderr io.Writer, src, dest fileSpec) error { <del> if len(src.File) == 0 { </del> <ins> if len(src.File) == 0 || len(dest.File) == 0 { </ins> return errFileCannotBeEmpty } reader, writer := io.Pipe() // strip trailing slash (if any) <del> if strings.HasSuffix(string(dest.File[len(dest.File)-1]), "/") { </del> <ins> if dest.File != "/" && strings.HasSuffix(string(dest.File[len(dest.File)-1]), "/") { </ins> dest.File = dest.File[:len(dest.File)-1] }

} func copyFromPod(f cmdutil.Factory, cmd *cobra.Command, cmderr io.Writer, src, dest fileSpec) error { <del> if len(src.File) == 0 { </del> <ins> if len(src.File) == 0 || len(dest.File) == 0 { </ins> return errFileCannotBeEmpty }

"bytes" "io" "io/ioutil" <ins> "net/http" </ins> "os" "os/exec" "path" "path/filepath" "strings" "testing" <ins> "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/rest/fake" "k8s.io/kubernetes/pkg/api/legacyscheme" cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing" "k8s.io/kubernetes/pkg/kubectl/scheme" </ins> ) type FileType int

} } } <ins> func TestCopyToPod(t *testing.T) { tf := cmdtesting.NewTestFactory() tf.Namespace = "test" ns := legacyscheme.Codecs codec := legacyscheme.Codecs.LegacyCodec(scheme.Versions...) tf.Client = &fake.RESTClient{ GroupVersion:         schema.GroupVersion{Group: "", Version: "v1"}, NegotiatedSerializer: ns, Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { responsePod := &v1.Pod{} return &http.Response{StatusCode: http.StatusNotFound, Header: defaultHeader(), Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(codec, responsePod))))}, nil }), } tf.ClientConfigVal = defaultClientConfig() buf := bytes.NewBuffer([]byte{}) errBuf := bytes.NewBuffer([]byte{}) cmd := NewCmdCp(tf, buf, errBuf) srcFile, err := ioutil.TempDir("", "test") if err != nil { t.Errorf("unexpected error: %v", err) t.FailNow() } defer os.RemoveAll(srcFile) tests := map[string]struct { dest        string expectedErr bool }{ "copy to directory": { dest:        "/tmp/", expectedErr: false, }, "copy to root": { dest:        "/", expectedErr: false, }, "copy to empty file name": { dest:        "", expectedErr: true, }, } for name, test := range tests { src := fileSpec{ File: srcFile, } dest := fileSpec{ PodNamespace: "pod-ns", PodName:      "pod-name", File:         test.dest, } t.Run(name, func(t *testing.T) { err = copyToPod(tf, cmd, buf, errBuf, src, dest) //If error is NotFound error , it indicates that the //request has been sent correctly. //Treat this as no error. if test.expectedErr && errors.IsNotFound(err) { t.Errorf("expected error but didn't get one") } if !test.expectedErr && !errors.IsNotFound(err) { t.Errorf("unexpected error: %v", err) } }) } } </ins>