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!--What happened: retry azure disk attach operation produce too many API calls Not the default value is 6 which means if AttachDisk operation failed, it will retry 6 more times, when disk quota is full on a VM, it produces too many API calls. Retry attach disk behavior is not necessary since it AttachVolume operation fails, k8s attachdetach-controller will retry once a minute until it succeeds. default setting in 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 ): v1.10, v1.11, v1.12 Cloud provider or hardware configuration: OS (e.g. from /etc/os-release): Kernel (e.g. ): Install tools: Others: <!-- DO NOT EDIT BELOW THIS LINE --/kind bug /sig azure /assign

Discussion:
}, }, } <del> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk", nodeResourceGroup, vmName) </del> <ins> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, vmName, diskName) </ins> ctx, cancel := getContextWithCancel() defer cancel() <del> resp, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM) if as.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) { glog.V(2).Infof("azureDisk - update(%s) backing off: vm(%s)", nodeResourceGroup, vmName) retryErr := as.CreateOrUpdateVMWithRetry(nodeResourceGroup, vmName, newVM) if retryErr != nil { err = retryErr glog.V(2).Infof("azureDisk - update(%s) abort backoff: vm(%s)", nodeResourceGroup, vmName) } } if err != nil { glog.Errorf("azureDisk - azure attach failed, err: %v", err) </del> <ins> if _, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM); err != nil { glog.Errorf("azureDisk - attach disk(%s) failed, err: %v", diskName, err) </ins> detail := err.Error() if strings.Contains(detail, errLeaseFailed) || strings.Contains(detail, errDiskBlobNotFound) { // if lease cannot be acquired or disk not found, immediately detach the disk and return the original error <del> glog.Infof("azureDisk - err %s, try detach", detail) </del> <ins> glog.V(2).Infof("azureDisk - err %v, try detach disk(%s)", err, diskName) </ins> as.DetachDiskByName(diskName, diskURI, nodeName) } } else { <del> glog.V(4).Info("azureDisk - azure attach succeeded") </del> <ins> glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName) </ins> // Invalidate the cache right after updating as.cloud.vmCache.Delete(vmName) }

}, }, } <del> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk", nodeResourceGroup, vmName) </del> <ins> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, vmName, diskName) </ins> ctx, cancel := getContextWithCancel() defer cancel() <del> resp, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM) if as.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) { glog.V(2).Infof("azureDisk - update(%s) backing off: vm(%s)", nodeResourceGroup, vmName) retryErr := as.CreateOrUpdateVMWithRetry(nodeResourceGroup, vmName, newVM) if retryErr != nil { err = retryErr glog.V(2).Infof("azureDisk - update(%s) abort backoff: vm(%s)", nodeResourceGroup, vmName) } } if err != nil { glog.Errorf("azureDisk - azure disk detach failed, err: %v", err) </del> <ins> if _, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM); err != nil { glog.Errorf("azureDisk - detach disk(%s) failed, err: %v", diskName, err) </ins> } else { <del> glog.V(4).Info("azureDisk - azure disk detach succeeded") </del> <ins> glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName) </ins> // Invalidate the cache right after updating as.cloud.vmCache.Delete(vmName) }

ctx, cancel := getContextWithCancel() defer cancel() <del> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk", nodeResourceGroup, nodeName) resp, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm) if ss.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) { glog.V(2).Infof("azureDisk - update(%s) backing off: vm(%s)", nodeResourceGroup, nodeName) retryErr := ss.UpdateVmssVMWithRetry(ctx, nodeResourceGroup, ssName, instanceID, vm) if retryErr != nil { err = retryErr glog.V(2).Infof("azureDisk - update(%s) abort backoff: vm(%s)", nodeResourceGroup, nodeName) } } if err != nil { </del> <ins> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, nodeName, diskName) if _, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm); err != nil { </ins> detail := err.Error() if strings.Contains(detail, errLeaseFailed) || strings.Contains(detail, errDiskBlobNotFound) { // if lease cannot be acquired or disk not found, immediately detach the disk and return the original error <del> glog.Infof("azureDisk - err %s, try detach", detail) </del> <ins> glog.Infof("azureDisk - err %s, try detach disk(%s)", detail, diskName) </ins> ss.DetachDiskByName(diskName, diskURI, nodeName) } } else { <del> glog.V(4).Info("azureDisk - azure attach succeeded") </del> <ins> glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName) </ins> // Invalidate the cache right after updating key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID)) ss.vmssVMCache.Delete(key)

(disk.Vhd != nil && disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) || (disk.ManagedDisk != nil && diskURI != "" && *disk.ManagedDisk.ID == diskURI) { // found the disk <del> glog.V(4).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI) </del> <ins> glog.V(2).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI) </ins> disks = append(disks[:i], disks[i+1:]...) bFoundDisk = true break

vm.StorageProfile.DataDisks = &disks ctx, cancel := getContextWithCancel() defer cancel() <del> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk", nodeResourceGroup, nodeName) resp, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm) if ss.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) { glog.V(2).Infof("azureDisk - update(%s) backing off: vm(%s)", nodeResourceGroup, nodeName) retryErr := ss.UpdateVmssVMWithRetry(ctx, nodeResourceGroup, ssName, instanceID, vm) if retryErr != nil { err = retryErr glog.V(2).Infof("azureDisk - update(%s) abort backoff: vm(%s)", nodeResourceGroup, nodeName) } } if err != nil { glog.Errorf("azureDisk - azure disk detach %q from %s failed, err: %v", diskName, nodeName, err) </del> <ins> glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, nodeName, diskName) if _, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm); err != nil { glog.Errorf("azureDisk - detach disk(%s) from %s failed, err: %v", diskName, nodeName, err) </ins> } else { <del> glog.V(4).Info("azureDisk - azure detach succeeded") </del> <ins> glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName) </ins> // Invalidate the cache right after updating key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID)) ss.vmssVMCache.Delete(key)