-
Notifications
You must be signed in to change notification settings - Fork 39.4k
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
Conversation
👋 happened to see this PR looking for another one ... If paths are for use in the container they should probably use |
@soltysh does this need to be in v1.19? If so, who do we need for lgtm? |
/hold for #94165 (comment) question |
/milestone v1.20 This is late for 1.19, can resolve in 1.19.x if needed |
where are we with this ? as per #94165 |
I'm verifying all the edge cases and should have the answer today/tomorrow at latest. |
/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)) |
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.
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.
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 have a test here:
kubernetes/staging/src/k8s.io/kubectl/pkg/cmd/cp/cp_test.go
Lines 55 to 112 in 28b46be
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) | |
} | |
} | |
} |
/retest |
1 similar comment
/retest |
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'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.
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:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
@tallclair @enj this should be ready for another round of reviews |
/remove-lifecycle stale |
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.
/lgtm
/approve
🎉
[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 |
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:
You can:
/retest |
…pstream-release-1.21 Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
…pstream-release-1.22 Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
…pstream-release-1.20 Automated cherry pick of #94165: Use separate pathSpec for local and remote to properly handle
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
andlocalPath
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?:
/sig cli
/priority important-longterm
/milestone v1.19