Description of problem: Run a pod container, try to copy file from local to a container's folder but not ended up with slash. Version-Release number of selected component (if applicable): oc v3.6.141 How reproducible: Always Steps to Reproduce: 1. $ touch test $ oc run mypod --image=aosqe/hello-openshift --generator='run-pod/v1' Then wait for pod Running. 2. $ oc cp test mypod:/tmp 3. (For compare) $ oc cp test mypod:/tmp/ $ oc rsh mypod ls /tmp test Actual results: 2. tar: can't open 'test': Permission denied command terminated with exit code 1 Expected results: Step 2 should be same with step 3 Additional info: # oc cp test mypod:/ tar: can't open 'test': Permission denied command terminated with exit code 1
Right now, `oc cp` does not actually check to see if the destination path you provided exists, is a directory, etc. We simply take the "directory" portion of your destination argument as described in https://golang.org/pkg/path/#Dir: [Example 1] Local Source File: "test" Destination: "mypod:/tmp/" Becomes: <in remote pod>$ tar xf - -C /tmp Meaning that we first change directory to "/tmp" before extracting the contents specified into the current working directory, using the original source filename "test". So you end up with a new file in the pod "/tmp/test". or [Example 2] Local Source File: "test" Destination: "mypod:/tmp" Becomes: <in remote pod>$ tar xf - -c / Meaning that we first change directory to "/" before extracting the contents into it using the original source name "test". Since we cannot create a new file named "test" in the root directory of the pod, we end up with the error: "tar: can't open 'test': Permission denied" A recent PR (https://github.com/openshift/origin/pull/15929) aims to update the copy command, such that the name you specify in your destination path is actually used. For example, given the following: Local Source File: "test" Destination: "mypod:/tmp/mycustomname" You would copy the local file "test" under a new file "/tmp/mycustomname" in the remote pod (right now, the file gets copied under "/tmp/test" in the pod, and "mycustomname" is ignored). With this in mind, I could update the existing PR (15929) to additionally check for a trailing "/" in the destination path, such that if you have the following: Local Source File: "test" Destination: "mypod:/tmp/" The current behavior of using the Local Source File name is kept. So you would end up with a new file "/tmp/test" in the remote pod. Because the command does not check if "tmp" already exists and is a directory in the remote pod, without a trailing "/", [Example 2] with the updated `oc cp` command (with patch 15929 applied) would now give the error "tar: tmp: Cannot open: File exists", meaning that in the root directory, there is already a file or directory named "tmp" (your chosen destination) and therefore is unable to proceed.
This has been addressed by two related upstream PRs: - https://github.com/kubernetes/kubernetes/pull/51215 - https://github.com/kubernetes/kubernetes/pull/52465 Marking as UpcomingRelease
Like bug 1469411, this bug is fixed in v3.9, pls help move to ON_QA, thanks
Verified on oc v3.9.0-0.16.0 For step3: $ oc cp test1 mypod:/tmp/ $ oc rsh mypod ls /tmp test1 For step2: $ oc cp test2 mypod:/tmp $ oc rsh mypod ls /tmp test1 test2