Skip to content

Commit e287390

Browse files
committed
fix devicePath issue in Azure WaitForAttach func
1 parent 4b26d70 commit e287390

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

pkg/volume/azure_dd/attacher.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"path/filepath"
2525
"runtime"
2626
"strconv"
27+
"strings"
2728
"time"
2829

2930
"github.com/Azure/azure-sdk-for-go/arm/compute"
@@ -150,9 +151,16 @@ func (a *azureDiskAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName ty
150151

151152
func (a *azureDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string, _ *v1.Pod, timeout time.Duration) (string, error) {
152153
var err error
153-
lun, err := strconv.Atoi(devicePath)
154-
if err != nil {
155-
return "", fmt.Errorf("azureDisk - Wait for attach expect device path as a lun number, instead got: %s (%v)", devicePath, err)
154+
newDevicePath := ""
155+
lun := -1
156+
157+
if strings.HasPrefix(devicePath, "/dev/") {
158+
newDevicePath = devicePath
159+
} else {
160+
lun, err = strconv.Atoi(devicePath)
161+
if err != nil {
162+
return "", fmt.Errorf("azureDisk - Wait for attach expect device path as a lun number, instead got: %s (%v)", devicePath, err)
163+
}
156164
}
157165

158166
volumeSource, err := getVolumeSource(spec)
@@ -167,18 +175,15 @@ func (a *azureDiskAttacher) WaitForAttach(spec *volume.Spec, devicePath string,
167175

168176
diskName := volumeSource.DiskName
169177
nodeName := a.plugin.host.GetHostName()
170-
newDevicePath := ""
171178

172179
err = wait.Poll(1*time.Second, timeout, func() (bool, error) {
173-
if newDevicePath, err = findDiskByLun(lun, io, exec); err != nil {
174-
return false, fmt.Errorf("azureDisk - WaitForAttach ticker failed node (%s) disk (%s) lun(%v) err(%s)", nodeName, diskName, lun, err)
180+
if newDevicePath == "" {
181+
if newDevicePath, err = findDiskByLun(lun, io, exec); err != nil {
182+
return false, fmt.Errorf("azureDisk - WaitForAttach ticker failed node (%s) disk (%s) lun(%v) err(%s)", nodeName, diskName, lun, err)
183+
}
175184
}
176185

177-
// did we find it?
178186
if newDevicePath != "" {
179-
// the current sequence k8s uses for unformated disk (check-disk, mount, fail, mkfs.extX) hangs on
180-
// Azure Managed disk scsi interface. this is a hack and will be replaced once we identify and solve
181-
// the root case on Azure.
182187
formatIfNotFormatted(newDevicePath, *volumeSource.FSType, exec)
183188
return true, nil
184189
}

0 commit comments

Comments
 (0)