fix azure disk lun error

This commit is contained in:
andyzhangx 2019-05-15 08:32:03 +00:00
parent adf6fa6987
commit 4213f4d797
4 changed files with 9 additions and 8 deletions

View File

@ -82,7 +82,7 @@ func (a *azureDiskAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (
klog.V(2).Infof("GetDiskLun returned: %v. Initiating attaching volume %q to node %q.", err, volumeSource.DataDiskURI, nodeName) klog.V(2).Infof("GetDiskLun returned: %v. Initiating attaching volume %q to node %q.", err, volumeSource.DataDiskURI, nodeName)
isManagedDisk := (*volumeSource.Kind == v1.AzureManagedDisk) isManagedDisk := (*volumeSource.Kind == v1.AzureManagedDisk)
err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode)) lun, err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode))
if err == nil { if err == nil {
klog.V(2).Infof("Attach operation successful: volume %q attached to node %q.", volumeSource.DataDiskURI, nodeName) klog.V(2).Infof("Attach operation successful: volume %q attached to node %q.", volumeSource.DataDiskURI, nodeName)
} else { } else {

View File

@ -44,7 +44,7 @@ type DiskController interface {
DeleteManagedDisk(diskURI string) error DeleteManagedDisk(diskURI string) error
// Attaches the disk to the host machine. // Attaches the disk to the host machine.
AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) error AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error)
// Detaches the disk, identified by disk name or uri, from the host machine. // Detaches the disk, identified by disk name or uri, from the host machine.
DetachDisk(diskName, diskUri string, nodeName types.NodeName) error DetachDisk(diskName, diskUri string, nodeName types.NodeName) error

View File

@ -91,16 +91,17 @@ func (c *controllerCommon) getNodeVMSet(nodeName types.NodeName) (VMSet, error)
} }
// AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI. // AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI.
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) error { // return (lun, error)
func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) {
vmset, err := c.getNodeVMSet(nodeName) vmset, err := c.getNodeVMSet(nodeName)
if err != nil { if err != nil {
return err return -1, err
} }
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName) instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
if err != nil { if err != nil {
klog.Warningf("failed to get azure instance id (%v)", err) klog.Warningf("failed to get azure instance id (%v)", err)
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err) return -1, fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
} }
diskOpMutex.LockKey(instanceid) diskOpMutex.LockKey(instanceid)
@ -109,11 +110,11 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
lun, err := c.GetNextDiskLun(nodeName) lun, err := c.GetNextDiskLun(nodeName)
if err != nil { if err != nil {
klog.Warningf("no LUN available for instance %q (%v)", nodeName, err) klog.Warningf("no LUN available for instance %q (%v)", nodeName, err)
return fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err) return -1, fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err)
} }
klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName) klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName)
return vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode) return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode)
} }
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI. // DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.

View File

@ -36,7 +36,7 @@ func TestAttachDisk(t *testing.T) {
diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/disk-name", c.SubscriptionID, c.ResourceGroup) diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/disk-name", c.SubscriptionID, c.ResourceGroup)
err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly) _, err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly)
if err != nil { if err != nil {
fmt.Printf("TestAttachDisk return expected error: %v", err) fmt.Printf("TestAttachDisk return expected error: %v", err)
} else { } else {