-
Notifications
You must be signed in to change notification settings - Fork 61
Add GetClosestVolumeIDFromTargetPath API to the Volume API Group #189
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
Add GetClosestVolumeIDFromTargetPath API to the Volume API Group #189
Conversation
e11660c
to
3fdd2b3
Compare
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.
Recommend tightening the prefix check for Volume. I think the Volume prefix check in k/k should also be tightened with a regex.
pkg/os/volume/api.go
Outdated
return "", err | ||
} | ||
// if it has the form Volume{volumeid}\ then it's a volume | ||
if strings.HasPrefix(target, "Volume") { |
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 feel the Volume prefix check can be tightened with a regex to exactly match Volume{...}
format. If a disk layout has symlink chains with links named VolumeData1
and VolumeData2
that are actually links to Volume{A}
and Volume{B}
, the HasPrefix
logic would return incorrect results.
3fdd2b3
to
37b2188
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ddebroy, mauriciopoppe 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 |
37b2188
to
35df0f2
Compare
35df0f2
to
1b1140c
Compare
/test pull-kubernetes-csi-csi-proxy-integration |
1b1140c
to
93372a3
Compare
/test pull-kubernetes-csi-csi-proxy-integration |
93372a3
to
56a7c10
Compare
/test pull-kubernetes-csi-csi-proxy-integration |
/hold cancel pull-kubernetes-csi-csi-proxy-integration passed, @jingxu97 it's now ready for review |
pkg/os/volume/api.go
Outdated
func dereferenceSymlink(path string) (string, error) { | ||
cmd := exec.Command("powershell", "/c", fmt.Sprintf(`(Get-Item -Path %s).Target`, path)) | ||
klog.V(8).Infof("About to execute: %q", cmd.String()) | ||
targetb, err := cmd.Output() |
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.
not sure it is the case, sometimes the error is empty, but command actually return some error messages, so targetb will be some strings. In this case just want to make sure the logic can handle it.
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.
true, cmd.Output
returns the combined output, places where this is called ensure that the path sent is a symlink however another way to test it would be by analyzing stderr apart from stdout.
The existing GetVolumeIDFromTargetPath
doesn't do a separate analysis either, it's using the combined output and relying on err for errors
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 just wondering whether it is possible to make sure it return a valid path or a volume id, instead of some long string
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 think that if the target doesn't exist it'll return an error that's propagated, so at this point we know that it's a path or a volumeId, for anything in stderr I'm not checking though, I'll only analyze the output of stdout and error if stderr has contents
56a7c10
to
424410a
Compare
pkg/os/volume/api.go
Outdated
// if it has the form Volume{volumeid} then it's a volume | ||
if VolumeRegexp.Match([]byte(target)) { | ||
// symlinks that are pointing to Volumes don't have this prefix | ||
target = "\\\\?\\" + target |
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.
should we check prefix just in case before adding it?
424410a
to
9318567
Compare
9318567
to
c0f1eb7
Compare
/lgtm |
What type of PR is this?
/kind api-change
/kind feature
What this PR does / why we need it:
Adds the new Volume API,
GetClosestVolumeIDFromTargetPath
, it allows getting the closest volume from a target path handling more scenarios as described below.The algorithm is:
Volume{
then its a volume, return itIn the following example all the calls to
GetClosestVolumeIDFromTargetPath
are with paths inside/mnt/disks
:Does this PR introduce a user-facing change?:
/hold
Depends on #188
/cc @jingxu97 @ddebroy @msau42