Skip to content

Commit 4213f4d

Browse files
committed
fix azure disk lun error
1 parent adf6fa6 commit 4213f4d

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

pkg/volume/azure_dd/attacher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (a *azureDiskAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (
8282
klog.V(2).Infof("GetDiskLun returned: %v. Initiating attaching volume %q to node %q.", err, volumeSource.DataDiskURI, nodeName)
8383

8484
isManagedDisk := (*volumeSource.Kind == v1.AzureManagedDisk)
85-
err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode))
85+
lun, err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode))
8686
if err == nil {
8787
klog.V(2).Infof("Attach operation successful: volume %q attached to node %q.", volumeSource.DataDiskURI, nodeName)
8888
} else {

pkg/volume/azure_dd/azure_dd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type DiskController interface {
4444
DeleteManagedDisk(diskURI string) error
4545

4646
// Attaches the disk to the host machine.
47-
AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) error
47+
AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error)
4848
// Detaches the disk, identified by disk name or uri, from the host machine.
4949
DetachDisk(diskName, diskUri string, nodeName types.NodeName) error
5050

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_common.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,17 @@ func (c *controllerCommon) getNodeVMSet(nodeName types.NodeName) (VMSet, error)
9191
}
9292

9393
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI.
94-
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) error {
94+
// return (lun, error)
95+
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
9596
vmset, err := c.getNodeVMSet(nodeName)
9697
if err != nil {
97-
return err
98+
return -1, err
9899
}
99100

100101
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
101102
if err != nil {
102103
klog.Warningf("failed to get azure instance id (%v)", err)
103-
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
104+
return -1, fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
104105
}
105106

106107
diskOpMutex.LockKey(instanceid)
@@ -109,11 +110,11 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
109110
lun, err := c.GetNextDiskLun(nodeName)
110111
if err != nil {
111112
klog.Warningf("no LUN available for instance %q (%v)", nodeName, err)
112-
return fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err)
113+
return -1, fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err)
113114
}
114115

115116
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
116-
return vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode)
117+
return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode)
117118
}
118119

119120
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.

staging/src/k8s.io/legacy-cloud-providers/azure/azure_controller_common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAttachDisk(t *testing.T) {
3636

3737
diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/disk-name", c.SubscriptionID, c.ResourceGroup)
3838

39-
err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly)
39+
_, err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly)
4040
if err != nil {
4141
fmt.Printf("TestAttachDisk return expected error: %v", err)
4242
} else {

0 commit comments

Comments
 (0)