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

Use separate pathSpec for local and remote to properly handle cleaning paths #94165

Merged
merged 1 commit into from
Oct 19, 2021

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Aug 21, 2020

What type of PR is this?
/kind bug

What this PR does / why we need it:
We should be consistently be using https://golang.org/pkg/path/filepath/ instead of https://golang.org/pkg/path/ when working with paths.

This PR defines remotePath and localPath type which properly handles os-related operations such as cleaning, joining paths, etc.

Special notes for your reviewer:
/assign @sallyom @seans3

Does this PR introduce a user-facing change?:

NONE

/sig cli
/priority important-longterm
/milestone v1.19

@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/M Denotes a PR that changes 30-99 lines, ignoring generated files. sig/cli Categorizes an issue or PR as relevant to SIG CLI. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. labels Aug 21, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Aug 21, 2020
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 21, 2020
@k8s-ci-robot k8s-ci-robot added area/kubectl approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 21, 2020
@BenTheElder
Copy link
Member

👋 happened to see this PR looking for another one ...

If paths are for use in the container they should probably use path instead of filepath, it should be good enough in general to handle POSIX paths, but if you use filepath for container paths then it will break when the client is windows.

@hasheddan
Copy link
Contributor

@soltysh does this need to be in v1.19? If so, who do we need for lgtm?

@liggitt
Copy link
Member

liggitt commented Aug 25, 2020

/hold for #94165 (comment) question

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 25, 2020
@liggitt
Copy link
Member

liggitt commented Aug 25, 2020

/milestone v1.20

This is late for 1.19, can resolve in 1.19.x if needed

@k8s-ci-robot k8s-ci-robot modified the milestones: v1.19, v1.20 Aug 25, 2020
@justaugustus justaugustus modified the milestones: v1.20, v1.20-phase-bug Aug 27, 2020
@justaugustus justaugustus modified the milestones: v1.20-phase-bug, v1.20 Sep 8, 2020
@lukehinds
Copy link

where are we with this ? as per #94165 filepath is problematic for windows, so it sounds like we need to approach this fix with a different approach?

@soltysh
Copy link
Contributor Author

soltysh commented Oct 13, 2020

where are we with this ? as per #94165 filepath is problematic for windows, so it sounds like we need to approach this fix with a different approach?

I'm verifying all the edge cases and should have the answer today/tomorrow at latest.

@soltysh
Copy link
Contributor Author

soltysh commented Oct 15, 2020

/retest

@@ -138,7 +137,7 @@ func extractFileSpec(arg string) (fileSpec, error) {
}

pod, file := arg[:i], arg[i+1:]
pieces := strings.Split(pod, "/")
pieces := strings.Split(pod, string(filepath.Separator))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not right, the pod name is either <pod> or <namespace>/<pod>, so this should continue to split on "/"

See the documented example:

kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

If a test did not catch this, then we need to add a test explicitly for this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a test here:

func TestExtractFileSpec(t *testing.T) {
tests := []struct {
spec string
expectedPod string
expectedNamespace string
expectedFile string
expectErr bool
}{
{
spec: "namespace/pod:/some/file",
expectedPod: "pod",
expectedNamespace: "namespace",
expectedFile: "/some/file",
},
{
spec: "pod:/some/file",
expectedPod: "pod",
expectedFile: "/some/file",
},
{
spec: "/some/file",
expectedFile: "/some/file",
},
{
spec: ":file:not:exist:in:local:filesystem",
expectErr: true,
},
{
spec: "namespace/pod/invalid:/some/file",
expectErr: true,
},
{
spec: "pod:/some/filenamewith:in",
expectedPod: "pod",
expectedFile: "/some/filenamewith:in",
},
}
for _, test := range tests {
spec, err := extractFileSpec(test.spec)
if test.expectErr && err == nil {
t.Errorf("unexpected non-error")
continue
}
if err != nil && !test.expectErr {
t.Errorf("unexpected error: %v", err)
continue
}
if spec.PodName != test.expectedPod {
t.Errorf("expected: %s, saw: %s", test.expectedPod, spec.PodName)
}
if spec.PodNamespace != test.expectedNamespace {
t.Errorf("expected: %s, saw: %s", test.expectedNamespace, spec.PodNamespace)
}
if spec.File != test.expectedFile {
t.Errorf("expected: %s, saw: %s", test.expectedFile, spec.File)
}
}
}
but since we're running that on a linux machine it works just fine.

@soltysh
Copy link
Contributor Author

soltysh commented May 24, 2021

/retest

1 similar comment
@soltysh
Copy link
Contributor Author

soltysh commented Jun 15, 2021

/retest

Copy link
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really sorry I've been so delinquent on this review.

I have a few suggestions around making the path types explicit where we're expecting to be dealing with a specific path type.

staging/src/k8s.io/kubectl/pkg/cmd/cp/filespec.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/cp/cp.go Outdated Show resolved Hide resolved
staging/src/k8s.io/kubectl/pkg/cmd/cp/filespec.go Outdated Show resolved Hide resolved
@pacoxu pacoxu added this to Needs review in SIG CLI Sep 27, 2021
@pacoxu pacoxu moved this from Needs review to In progress in SIG CLI Sep 27, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Oct 7, 2021
@soltysh
Copy link
Contributor Author

soltysh commented Oct 13, 2021

@tallclair @enj this should be ready for another round of reviews

@soltysh
Copy link
Contributor Author

soltysh commented Oct 13, 2021

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 13, 2021
Copy link
Member

@tallclair tallclair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
🎉

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 18, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: soltysh, tallclair

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@tallclair tallclair removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 19, 2021
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit 6cbe185 into kubernetes:master Oct 19, 2021
SIG CLI automation moved this from In progress to Done Oct 19, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.23 milestone Oct 19, 2021
@soltysh soltysh deleted the fix_cp branch October 21, 2021 14:29
k8s-ci-robot added a commit that referenced this pull request Nov 9, 2021
…pstream-release-1.21

Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
k8s-ci-robot added a commit that referenced this pull request Nov 9, 2021
…pstream-release-1.22

Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
k8s-ci-robot added a commit that referenced this pull request Nov 9, 2021
…pstream-release-1.20

Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. 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. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

None yet