Change:
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks! If the matter is security related, please disclose it privately via --What happened: What you expected to happen: How to reproduce it (as minimally and precisely as possible): Anything else we need to know?: Environment: Kubernetes version (use ): Cloud provider or hardware configuration: OS (e.g: ): Kernel (e.g. ): Install tools: Network plugin and version (if this is a network-related bug): Others: /sig azure /assign

Discussion:
klog.V(2).Infof("GetDiskLun returned: %v. Initiating attaching volume %q to node %q.", err, volumeSource.DataDiskURI, nodeName) isManagedDisk := (*volumeSource.Kind == v1.AzureManagedDisk) <del> err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode)) </del> <ins> lun, err = diskController.AttachDisk(isManagedDisk, volumeSource.DiskName, volumeSource.DataDiskURI, nodeName, compute.CachingTypes(*volumeSource.CachingMode)) </ins> if err == nil { klog.V(2).Infof("Attach operation successful: volume %q attached to node %q.", volumeSource.DataDiskURI, nodeName) } else {

DeleteManagedDisk(diskURI string) error // Attaches the disk to the host machine. <del> AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) error </del> <ins> AttachDisk(isManagedDisk bool, diskName, diskUri string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) </ins> // Detaches the disk, identified by disk name or uri, from the host machine. DetachDisk(diskName, diskUri string, nodeName types.NodeName) error

} // AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI. <del> func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) error { </del> <ins> // return (lun, error) func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI string, nodeName types.NodeName, cachingMode compute.CachingTypes) (int32, error) { </ins> vmset, err := c.getNodeVMSet(nodeName) if err != nil { <del> return err </del> <ins> return -1, err </ins> } instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName) if err != nil { klog.Warningf("failed to get azure instance id (%v)", err) <del> return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err) </del> <ins> return -1, fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err) </ins> } diskOpMutex.LockKey(instanceid)

lun, err := c.GetNextDiskLun(nodeName) if err != nil { klog.Warningf("no LUN available for instance %q (%v)", nodeName, err) <del> return fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err) </del> <ins> return -1, fmt.Errorf("all LUNs are used, cannot attach volume (%s, %s) to instance %q (%v)", diskName, diskURI, instanceid, err) </ins> } klog.V(2).Infof("Trying to attach volume %q lun %d to node %q.", diskURI, lun, nodeName) <del> return vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode) </del> <ins> return lun, vmset.AttachDisk(isManagedDisk, diskName, diskURI, nodeName, lun, cachingMode) </ins> } // DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.

diskURI := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/disk-name", c.SubscriptionID, c.ResourceGroup) <del> err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly) </del> <ins> _, err := common.AttachDisk(true, "", diskURI, "node1", compute.CachingTypesReadOnly) </ins> if err != nil { fmt.Printf("TestAttachDisk return expected error: %v", err) } else {