Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

pswica
Copy link
Contributor

@pswica pswica commented Jun 7, 2019

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?:

Fixes a bug where kubectl cp could not copy to a folder directly on the host system. Also fixes a bug when copying to symlinked absolute paths.

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 7, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 7, 2019
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 7, 2019
@pswica
Copy link
Contributor Author

pswica commented Jun 7, 2019

/assign @janetkuo

@seans3
Copy link
Contributor

seans3 commented Jun 7, 2019

/assign soltysh

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Jun 8, 2019
@pswica
Copy link
Contributor Author

pswica commented Jun 8, 2019

/cc @draveness
would you be able to give this a review and start up a test?

@@ -280,6 +280,15 @@ func (o *CopyOptions) copyFromPod(src, dest fileSpec) error {
return errFileCannotBeEmpty
}

stat, err := os.Stat(dest.File)
Copy link
Contributor

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

Copy link
Contributor Author

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!

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 8, 2019
@dims
Copy link
Member

dims commented Jun 14, 2019

/assign @adohe

@k8s-ci-robot k8s-ci-robot removed the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 15, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 15, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pswica
To complete the pull request process, please assign adohe
You can assign the PR to them by writing /assign @adohe in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pswica pswica changed the title Kubectl cp error using kubectl version 1.14.2 #659 Kubectl cp error using kubectl version 1.14.2 #659 && kubectl cp fails on symlinks #78211 Jun 15, 2019
@pswica
Copy link
Contributor Author

pswica commented Jun 16, 2019

/retest

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 16, 2019
@pswica
Copy link
Contributor Author

pswica commented Jun 16, 2019

/retest

@pswica
Copy link
Contributor Author

pswica commented Jun 16, 2019

/retest

return "", err
}

if !os.IsNotExist(err) && stat.IsDir() {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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

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)
Copy link
Contributor

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

@booooh
Copy link

booooh commented Sep 1, 2019

Running into the same problem +1 for the fix

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 30, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 30, 2019
@k8s-ci-robot
Copy link
Contributor

@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.

@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kubectl cp error using kubectl version 1.14.2 kubectl cp fails on symlinks