New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kubectl cp error using kubectl version 1.14.2 #659 && kubectl cp fails on symlinks #78211 #78785
Conversation
Hi @pswica. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @janetkuo |
/assign soltysh |
/cc @draveness |
pkg/kubectl/cmd/cp/cp.go
Outdated
@@ -280,6 +280,15 @@ func (o *CopyOptions) copyFromPod(src, dest fileSpec) error { | |||
return errFileCannotBeEmpty | |||
} | |||
|
|||
stat, err := os.Stat(dest.File) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
/ok-to-test
/priority backlog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for taking the time to review!
/assign @adohe |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pswica The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/retest |
…tl cp fails on symlinks kubernetes#78211
/retest |
return "", err | ||
} | ||
|
||
if !os.IsNotExist(err) && stat.IsDir() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tar will append the right filename.
No need to do like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to do this to address the kubectl cp
bug that occurs now when you use to on a directory. That is why I need to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pswica Actually this is a bug of wrong prefix
when untar. We do have a file prefix checking there.
In https://github.com/kubernetes/kubernetes/pull/78928/files#diff-5103d5139d8d0e3143b6d7b6d1934f50R339, I've included a fix for this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I guess it depends where you think the logic should go in implementing the path that gets put into tar. I prefer my approach as it cleans everything before sending it to tar. This, to me, separates the logic between the two functions and makes them more loosely coupled .
Perhaps @liggitt or @siosphere can weigh in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dixudx another thing I'll mention, looking at your PR, is that it currently has a lot of failing tests:
I0616 14:51:04.155] should copy a file from a running Pod [It]
I0616 14:51:24.751] should copy a file from a running Pod [It]
I0616 14:53:57.520] runs ReplicaSets to verify preemption running path [It]
...
I don't think it would be fair to state that, at this moment, your solution fixes any bugs that mine fixes.
// If destination is a directory, filename will be the same as the source. | ||
// Also, symlink destinations are converted to true paths | ||
func convertHostDestFilename(srcFile string, destFile string) (string, error) { | ||
stat, err := os.Stat(destFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need to EvalSymlinks
for destFile here. No more steps are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The symlink steps were to address the other bug that my PR addresses, which is kubectl cp
failing to symlinks on full paths. Keeping those bugs I address in mind should make more clear why the code was created.
}, | ||
} | ||
for _, test := range tests { | ||
err := os.Mkdir(test.destFile, 755) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to create a temporary directory ioutil.TempDir
at the beginning of the test and then just clean it. See the first lines of TestTarUntarWrongPrefix
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/cp/cp_test.go
Lines 397 to 406 in 8dea331
dir, err := ioutil.TempDir("", "input") | |
checkErr(t, err) | |
dir2, err := ioutil.TempDir("", "output") | |
checkErr(t, err) | |
dir = dir + "/" | |
defer func() { | |
os.RemoveAll(dir) | |
os.RemoveAll(dir2) | |
}() |
func (o *CopyOptions) copyFromPod(src, dest fileSpec) error { | ||
if len(src.File) == 0 || len(dest.File) == 0 { | ||
return errFileCannotBeEmpty | ||
} | ||
|
||
d, err := convertHostDestFilename(src.File, dest.File) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created an alternative here: #81782
Running into the same problem +1 for the fix |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@pswica: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closed this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What type of PR is this?
/kind bug
What this PR does / why we need it:
Fixes kubernetes/kubectl#659
Which issue(s) this PR fixes:
Fixes #78211
Fixes kubernetes/kubectl#659
Special notes for your reviewer:
Does this PR introduce a user-facing change?: