Skip to content

Commit

Permalink
Don't trim device prefix for existing volumes in DeviceManager
Browse files Browse the repository at this point in the history
If a volume is (already) mounted at /dev/sdX, DM will trim the prefix
and claim the volume should be mounted at /dev/xvdX - this causes the
driver to get stuck in an infinite loop waiting for the volume to be
attached to the wrong location. This bug commonly is triggered by
manually mounting a volume using the AWS console, because it uses the
prefix /dev/sdX by default.

Signed-off-by: Connor Catlett <[email protected]>
  • Loading branch information
ConnorJC3 committed Feb 13, 2023
1 parent c4baaa7 commit 5afd743
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/cloud/devicemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ func (d *deviceManager) NewDevice(instance *ec2.Instance, volumeID string) (*Dev
return nil, err
}

name, err := d.nameAllocator.GetNext(inUse)
inUseTrimmed := make(map[string]string)
for key, name := range inUse {
// trims /dev/sd or /dev/xvd from device name
name = strings.TrimPrefix(name, "/dev/sd")
name = strings.TrimPrefix(name, "/dev/xvd")
inUseTrimmed[key] = name
}

name, err := d.nameAllocator.GetNext(inUseTrimmed)
if err != nil {
return nil, fmt.Errorf("could not get a free device name to assign to node %s", nodeID)
}
Expand Down Expand Up @@ -207,18 +215,11 @@ func (d *deviceManager) getDeviceNamesInUse(instance *ec2.Instance) map[string]s
inUse := map[string]string{}
for _, blockDevice := range instance.BlockDeviceMappings {
name := aws.StringValue(blockDevice.DeviceName)
// trims /dev/sd or /dev/xvd from device name
name = strings.TrimPrefix(name, "/dev/sd")
name = strings.TrimPrefix(name, "/dev/xvd")

if len(name) < 1 || len(name) > 2 {
klog.InfoS("Unexpected EBS DeviceName", "DeviceName", aws.StringValue(blockDevice.DeviceName))
}
inUse[name] = aws.StringValue(blockDevice.Ebs.VolumeId)
}

for name, volumeID := range d.inFlight.GetNames(nodeID) {
inUse[name] = volumeID
inUse[devPreffix+name] = volumeID
}

return inUse
Expand All @@ -227,7 +228,7 @@ func (d *deviceManager) getDeviceNamesInUse(instance *ec2.Instance) map[string]s
func (d *deviceManager) getPath(inUse map[string]string, volumeID string) string {
for name, volID := range inUse {
if volumeID == volID {
return devPreffix + name
return name
}
}
return ""
Expand Down

0 comments on commit 5afd743

Please sign in to comment.