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

Stop treating prefixes as magic in DeviceManager #1518

Merged
merged 3 commits into from
Mar 14, 2023

Conversation

ConnorJC3
Copy link
Contributor

DM treats the prefixes "/dev/xvd" and "/dev/sd" as magic. This leads to a bug where volumes with a prefix starting with "/dev/sd" (for example, "/dev/sdf") will get incorrectly mangled into a "/dev/xvd" form (i.e. converting "/dev/sdf" to "/dev/xvdf"). This will cause a volume that is already mounted and prefixed with "/dev/sd" (for example, a volume manually mounted via the AWS console) to get stuck in an infinite loop as the node will believe it is mounted at the wrong path.

With this change, instead of storing only the end of the path in the inflight and existing volumes map, we instead store the entire device path. The previously leaky abstraction from the allocator to store only the end of the path is contained to the allocator, which has a new parameter for the desired prefix.

This commit also vastly increases the range of paths the allocator can generate from 52 simultaneously mounted volumes to 650.

Signed-off-by: Connor Catlett [email protected]

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 2, 2023
@k8s-ci-robot k8s-ci-robot requested review from gtxu and rdpsin March 2, 2023 08:28
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 2, 2023
@rdpsin
Copy link
Contributor

rdpsin commented Mar 2, 2023

Please update the commit title to be more descriptive of the actual problem. 'Stop treating prefixes as magic' isn't very informative.

pkg/cloud/devicemanager/allocator_test.go Outdated Show resolved Hide resolved
@@ -22,8 +22,7 @@ import (

// ExistingNames is a map of assigned device names. Presence of a key with a device
// name in the map means that the device is allocated. Value is irrelevant and
// can be used for anything that NameAllocator user wants. Only the relevant
// part of device name should be in the map, e.g. "ba" for "/dev/xvdba".
// can be used for anything that NameAllocator user wants.
type ExistingNames map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't care about the value, it should be struct{}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although we don't care about the value there is a value: the caller passes in a map[string]string, which is not compatible with a map[string]struct{}.

@ConnorJC3 ConnorJC3 force-pushed the manually-attached branch from c1ac044 to bba5b11 Compare March 2, 2023 22:30
DM treats the prefixes "/dev/xvd" and "/dev/sd" as magic. This leads to
a bug where volumes with a prefix starting with "/dev/sd" (for example,
"/dev/sdf") will get incorrectly mangled into a "/dev/xvd" form (i.e.
converting "/dev/sdf" to "/dev/xvdf"). This will cause a volume that is
already mounted and prefixed with "/dev/sd" (for example, a volume
manually mounted via the AWS console) to get stuck in an infinite loop
as the node will believe it is mounted at the wrong path.

With this change, instead of storing only the end of the path in the
inflight and existing volumes map, we instead store the entire device
path. The previously leaky abstraction from the allocator to store only
the end of the path is contained to the allocator, which has a new
parameter for the desired prefix.

This commit also vastly increases the range of paths the allocator can
generate from 52 simultaneously mounted volumes to 650.

Signed-off-by: Connor Catlett <[email protected]>
@ConnorJC3 ConnorJC3 force-pushed the manually-attached branch from bba5b11 to 58fc07e Compare March 2, 2023 22:34
@torredil
Copy link
Member

torredil commented Mar 3, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 3, 2023
@torredil
Copy link
Member

torredil commented Mar 9, 2023

Will approve this PR tomorrow if no further feedback to include this change in our March release.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: torredil

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 Mar 10, 2023
@ConnorJC3
Copy link
Contributor Author

/hold needs fix

@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. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Mar 10, 2023
EBS has undocumented validation on the device that prevents the use of
device names after /dev/xvddx. Also, expand the beginning of the device
pool to account for this smaller pool of device names.

Signed-off-by: Connor Catlett <[email protected]>
@ConnorJC3
Copy link
Contributor Author

/remove-hold

Minor fix, but someone else should re-review before this is merged.

@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 Mar 10, 2023
@torredil
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2023
@torredil
Copy link
Member

torredil commented Mar 13, 2023

Blocked on kubernetes/test-infra#29003.

@torredil
Copy link
Member

/retest

1 similar comment
@torredil
Copy link
Member

/retest

@ConnorJC3
Copy link
Contributor Author

/retest
Flake?

@k8s-ci-robot k8s-ci-robot merged commit fd8b1e1 into kubernetes-sigs:master Mar 14, 2023
ConnorJC3 added a commit to ConnorJC3/aws-ebs-csi-driver that referenced this pull request Mar 27, 2023
Due to kubernetes-sigs#1518, volumes now start with /dev/xvda rather than /dev/xvdb.
Because of this, the hardcoded path in the snow code stopped working,
breaking mounting on snow devices. This change instead creates the
snow device path based on the last character of the generated path,
rather than trying to do it via trimming, which is unreliable.

Snow devices are currently limited to 10 volumes attached which makes
this 100% safe, but this will need to be revisited if snow every adds
suport for >26 volumes.

Signed-off-by: Connor Catlett <[email protected]>
ConnorJC3 added a commit to ConnorJC3/aws-ebs-csi-driver that referenced this pull request Mar 28, 2023
Due to kubernetes-sigs#1518, volumes now start with /dev/xvda rather than /dev/xvdb.
Because of this, the hardcoded path in the snow code stopped working,
breaking mounting on snow devices. This change instead creates the
snow device path based on the last character of the generated path,
rather than trying to do it via trimming, which is unreliable.

Snow devices are currently limited to 10 volumes attached which makes
this 100% safe, but this will need to be revisited if snow ever adds
suport for >26 volumes.

Signed-off-by: Connor Catlett <[email protected]>
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants