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
Failing closed after maximum retry is achieved to avoid inf recursion #336
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: knabben 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 |
Hi @knabben. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/assign @mauriciopoppe |
"testing" | ||
) | ||
|
||
func TestGetTarget(t *testing.T) { |
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 (and other calls) needs a real coverage
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.
Agreed, it'd be hard to setup a scenario with symlinks so that (Get-Item -Path $Env:mountpath).Target
works though.
/ok-to-test |
@jsturtevant: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
/ok-to-test |
@@ -268,7 +271,8 @@ func (VolumeAPI) GetDiskNumberFromVolumeID(volumeID string) (uint32, error) { | |||
|
|||
// GetVolumeIDFromTargetPath - gets the volume ID given a mount point, the function is recursive until it find a volume or errors out | |||
func (VolumeAPI) GetVolumeIDFromTargetPath(mount string) (string, error) { | |||
volumeString, err := getTarget(mount) | |||
var initialRetry = 1 |
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.
Nit: it could be just 0
@@ -54,6 +54,9 @@ var ( | |||
// PS C:\disks> (Get-Disk -Number 1 | Get-Partition | Get-Volume).UniqueId | |||
// \\?\Volume{452e318a-5cde-421e-9831-b9853c521012}\ | |||
VolumeRegexp = regexp.MustCompile(`Volume\{[\w-]*\}`) | |||
|
|||
// MaxGetTargetRetry defines the number of retries trying to get the correct volume target | |||
MaxGetTargetRetry = 3 |
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 3 is a very low number, in previous symlink dereferencing code I think we used 256 or maybe I read that in https://github.com/cyphar/filepath-securejoin/blob/main/join.go#L57
What about inlining the value where it's used?
cmd := `(Get-Item -Path $Env:mountpath).Target` | ||
cmdEnv := fmt.Sprintf("mountpath=%s", mount) | ||
out, err := utils.RunPowershellCmd(cmd, cmdEnv) | ||
if err != nil || len(out) == 0 { | ||
return "", fmt.Errorf("error getting volume from mount. cmd: %s, output: %s, error: %v", cmd, string(out), err) | ||
if err != nil || len(out) == 0 || retry >= MaxGetTargetRetry { |
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.
As an alternative we can hardcode it to retry == 256
} | ||
|
||
return ensureVolumePrefix(volumeString), nil | ||
} | ||
|
||
// GetVolumeIDFromTargetPath returns the volume id of a given target path. | ||
// GetClosestVolumeIDFromTargetPath returns the volume id of a given target path. |
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.
Thanks for fixing this!
cmd := `(Get-Item -Path $Env:mountpath).Target` | ||
cmdEnv := fmt.Sprintf("mountpath=%s", mount) | ||
out, err := utils.RunPowershellCmd(cmd, cmdEnv) | ||
if err != nil || len(out) == 0 { | ||
return "", fmt.Errorf("error getting volume from mount. cmd: %s, output: %s, error: %v", cmd, string(out), err) | ||
if err != nil || len(out) == 0 || retry >= MaxGetTargetRetry { |
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 can have many ifs, that way we know which was the actual reason e.g.
if err != nil {
// error message
}
if len(out) == 0 {
// no length error message
}
if retry == 256 {
// max recursion reached error message
}
"testing" | ||
) | ||
|
||
func TestGetTarget(t *testing.T) { |
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.
Agreed, it'd be hard to setup a scenario with symlinks so that (Get-Item -Path $Env:mountpath).Target
works though.
} | ||
|
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.
For debugging purposes of #193 (comment) maybe you could add
klog.V(8).Infof("retry: %d, volumeString: %s", retry, volumeString)
And start the server with very high verbosity
@knabben: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
What type of PR is this?
What this PR does / why we need it:
Adding a maximum retry for the CSI to find the volume target from a mountpath.
Which issue(s) this PR fixes:
Fixes #193
Special notes for your reviewer:
Tracking the recursion call trace here:
#193 (comment)
Does this PR introduce a user-facing change?: