mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #70568 from andyzhangx/remove-retry-azuredisk
remove retry operation on attach/detach azure disk
This commit is contained in:
commit
0f3dff251e
@ -73,28 +73,19 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk", nodeResourceGroup, vmName)
|
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, vmName, diskName)
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
resp, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM)
|
if _, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM); err != nil {
|
||||||
if as.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) {
|
glog.Errorf("azureDisk - attach disk(%s) failed, err: %v", diskName, 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)
|
|
||||||
detail := err.Error()
|
detail := err.Error()
|
||||||
if strings.Contains(detail, errLeaseFailed) || strings.Contains(detail, errDiskBlobNotFound) {
|
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
|
// if lease cannot be acquired or disk not found, immediately detach the disk and return the original error
|
||||||
glog.Infof("azureDisk - err %s, try detach", detail)
|
glog.V(2).Infof("azureDisk - err %v, try detach disk(%s)", err, diskName)
|
||||||
as.DetachDiskByName(diskName, diskURI, nodeName)
|
as.DetachDiskByName(diskName, diskURI, nodeName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Info("azureDisk - azure attach succeeded")
|
glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
|
||||||
// Invalidate the cache right after updating
|
// Invalidate the cache right after updating
|
||||||
as.cloud.vmCache.Delete(vmName)
|
as.cloud.vmCache.Delete(vmName)
|
||||||
}
|
}
|
||||||
@ -124,7 +115,7 @@ func (as *availabilitySet) DetachDiskByName(diskName, diskURI string, nodeName t
|
|||||||
(disk.Vhd != nil && disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) ||
|
(disk.Vhd != nil && disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) ||
|
||||||
(disk.ManagedDisk != nil && diskURI != "" && *disk.ManagedDisk.ID == diskURI) {
|
(disk.ManagedDisk != nil && diskURI != "" && *disk.ManagedDisk.ID == diskURI) {
|
||||||
// found the disk
|
// found the disk
|
||||||
glog.V(4).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
|
glog.V(2).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
|
||||||
disks = append(disks[:i], disks[i+1:]...)
|
disks = append(disks[:i], disks[i+1:]...)
|
||||||
bFoundDisk = true
|
bFoundDisk = true
|
||||||
break
|
break
|
||||||
@ -143,22 +134,13 @@ func (as *availabilitySet) DetachDiskByName(diskName, diskURI string, nodeName t
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk", nodeResourceGroup, vmName)
|
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, vmName, diskName)
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
resp, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM)
|
if _, err := as.VirtualMachinesClient.CreateOrUpdate(ctx, nodeResourceGroup, vmName, newVM); err != nil {
|
||||||
if as.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) {
|
glog.Errorf("azureDisk - detach disk(%s) failed, err: %v", diskName, 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)
|
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Info("azureDisk - azure disk detach succeeded")
|
glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
|
||||||
// Invalidate the cache right after updating
|
// Invalidate the cache right after updating
|
||||||
as.cloud.vmCache.Delete(vmName)
|
as.cloud.vmCache.Delete(vmName)
|
||||||
}
|
}
|
||||||
|
@ -71,25 +71,16 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
|||||||
|
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk", nodeResourceGroup, nodeName)
|
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - attach disk(%s)", nodeResourceGroup, nodeName, diskName)
|
||||||
resp, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm)
|
if _, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm); err != nil {
|
||||||
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 {
|
|
||||||
detail := err.Error()
|
detail := err.Error()
|
||||||
if strings.Contains(detail, errLeaseFailed) || strings.Contains(detail, errDiskBlobNotFound) {
|
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
|
// if lease cannot be acquired or disk not found, immediately detach the disk and return the original error
|
||||||
glog.Infof("azureDisk - err %s, try detach", detail)
|
glog.Infof("azureDisk - err %s, try detach disk(%s)", detail, diskName)
|
||||||
ss.DetachDiskByName(diskName, diskURI, nodeName)
|
ss.DetachDiskByName(diskName, diskURI, nodeName)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Info("azureDisk - azure attach succeeded")
|
glog.V(2).Infof("azureDisk - attach disk(%s) succeeded", diskName)
|
||||||
// Invalidate the cache right after updating
|
// Invalidate the cache right after updating
|
||||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||||
ss.vmssVMCache.Delete(key)
|
ss.vmssVMCache.Delete(key)
|
||||||
@ -121,7 +112,7 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
|
|||||||
(disk.Vhd != nil && disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) ||
|
(disk.Vhd != nil && disk.Vhd.URI != nil && diskURI != "" && *disk.Vhd.URI == diskURI) ||
|
||||||
(disk.ManagedDisk != nil && diskURI != "" && *disk.ManagedDisk.ID == diskURI) {
|
(disk.ManagedDisk != nil && diskURI != "" && *disk.ManagedDisk.ID == diskURI) {
|
||||||
// found the disk
|
// found the disk
|
||||||
glog.V(4).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
|
glog.V(2).Infof("azureDisk - detach disk: name %q uri %q", diskName, diskURI)
|
||||||
disks = append(disks[:i], disks[i+1:]...)
|
disks = append(disks[:i], disks[i+1:]...)
|
||||||
bFoundDisk = true
|
bFoundDisk = true
|
||||||
break
|
break
|
||||||
@ -135,20 +126,11 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
|
|||||||
vm.StorageProfile.DataDisks = &disks
|
vm.StorageProfile.DataDisks = &disks
|
||||||
ctx, cancel := getContextWithCancel()
|
ctx, cancel := getContextWithCancel()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk", nodeResourceGroup, nodeName)
|
glog.V(2).Infof("azureDisk - update(%s): vm(%s) - detach disk(%s)", nodeResourceGroup, nodeName, diskName)
|
||||||
resp, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm)
|
if _, err := ss.VirtualMachineScaleSetVMsClient.Update(ctx, nodeResourceGroup, ssName, instanceID, vm); err != nil {
|
||||||
if ss.CloudProviderBackoff && shouldRetryHTTPRequest(resp, err) {
|
glog.Errorf("azureDisk - detach disk(%s) from %s failed, err: %v", diskName, nodeName, 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)
|
|
||||||
} else {
|
} else {
|
||||||
glog.V(4).Info("azureDisk - azure detach succeeded")
|
glog.V(2).Infof("azureDisk - detach disk(%s) succeeded", diskName)
|
||||||
// Invalidate the cache right after updating
|
// Invalidate the cache right after updating
|
||||||
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
key := buildVmssCacheKey(nodeResourceGroup, ss.makeVmssVMName(ssName, instanceID))
|
||||||
ss.vmssVMCache.Delete(key)
|
ss.vmssVMCache.Delete(key)
|
||||||
|
Loading…
Reference in New Issue
Block a user