Skip to content

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

Conversation

mauriciopoppe
Copy link
Member

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

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

  • given a target path do the following for a max of 256 iterations (1)
    • if it's a symlink and has the form Volume{ then its a volume, return it
    • if it's a symlink and points to a location that exists then follow it and go to 1
    • if it's not a symlink then move up one level in the hierarchy and go to 1
    • if after moving one level up we get to the same location then we're at the root, return the volume corresponding to the boot disk

In the following example all the calls to GetClosestVolumeIDFromTargetPath are with paths inside /mnt/disks:

/               (Volume{A}) # boot disk
/foo/bar
/mnt/volume/  (symlink -> Volume{B})
  shared-disk/
     foo/bar/shared0/
     shared1/
/mnt/single0/ (symlink -> Volume{C})  # standalone disk
/mnt/disks/ (discovery directory)
  shared0/ (symlink -> /mnt/volume/shared-disk/foo/bar/shared0) # returns Volume{B}
  shared1/ (symlink -> /mnt/volume/shared-disk/shared1) # returns Volume{B}
  single0/ (symlink -> /mnt/single0) # returns Volume{C}
  volume0/ (symlink -> Volume{D}) # returns Volume{D}
  boot0/   (symlink -> /foo/bar) # returns Volume{A}

Does this PR introduce a user-facing change?:

Add Volume API GetClosestVolumeIDFromTargetPath to find the closest Volume from a given path.

/hold

Depends on #188

/cc @jingxu97 @ddebroy @msau42

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 7, 2022
@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch 2 times, most recently from e11660c to 3fdd2b3 Compare January 8, 2022 00:03
Copy link
Contributor

@ddebroy ddebroy left a 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.

return "", err
}
// if it has the form Volume{volumeid}\ then it's a volume
if strings.HasPrefix(target, "Volume") {
Copy link
Contributor

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.

@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 3fdd2b3 to 37b2188 Compare January 8, 2022 06:08
@ddebroy
Copy link
Contributor

ddebroy commented Jan 11, 2022

/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 Jan 11, 2022
@k8s-ci-robot
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 11, 2022
@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 37b2188 to 35df0f2 Compare January 14, 2022 01:41
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 14, 2022
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 19, 2022
@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 35df0f2 to 1b1140c Compare January 24, 2022 23:44
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 24, 2022
@mauriciopoppe
Copy link
Member Author

/test pull-kubernetes-csi-csi-proxy-integration

@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 1b1140c to 93372a3 Compare January 25, 2022 00:16
@mauriciopoppe
Copy link
Member Author

/test pull-kubernetes-csi-csi-proxy-integration

@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 93372a3 to 56a7c10 Compare January 25, 2022 18:54
@mauriciopoppe
Copy link
Member Author

/test pull-kubernetes-csi-csi-proxy-integration

@mauriciopoppe
Copy link
Member Author

/hold cancel

pull-kubernetes-csi-csi-proxy-integration passed, @jingxu97 it's now ready for review

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 25, 2022
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()
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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

Copy link
Member Author

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

@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 56a7c10 to 424410a Compare January 28, 2022 22:26
// 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
Copy link
Contributor

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?

@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 424410a to 9318567 Compare January 31, 2022 22:14
@mauriciopoppe mauriciopoppe force-pushed the closest-volume-from-target-path-volume-api branch from 9318567 to c0f1eb7 Compare January 31, 2022 22:19
@jingxu97
Copy link
Contributor

jingxu97 commented Feb 1, 2022

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 1, 2022
@k8s-ci-robot k8s-ci-robot merged commit 74279e7 into kubernetes-csi:master Feb 1, 2022
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants