mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-17 15:50:10 +00:00
Azure: Filter disks with ToBeDetached flag from attach/detach
After the detach calls are made, any further updates with the disks in the process of getting detached will complain with errors such as: " Cannot attach data disk '<disk name>' to VM '<vm name>' because the disk's ToBeDetached flag is set to true. Please either remove the disk from APIModel or set the ToBeDetached flag to false and then try again " This PR will ensure that the disks with the ToBeDetached flag set are filtered out before the update to the cloud is made.
This commit is contained in:
parent
268663c9e3
commit
c6b8207bfe
@ -302,3 +302,17 @@ func (c *controllerCommon) DisksAreAttached(diskNames []string, nodeName types.N
|
||||
|
||||
return attached, nil
|
||||
}
|
||||
|
||||
func filterDetachingDisks(unfilteredDisks []compute.DataDisk) []compute.DataDisk {
|
||||
filteredDisks := []compute.DataDisk{}
|
||||
for _, disk := range unfilteredDisks {
|
||||
if disk.ToBeDetached != nil && *disk.ToBeDetached {
|
||||
if disk.Name != nil {
|
||||
klog.V(2).Infof("Filtering disk: %s with ToBeDetached flag set.", *disk.Name)
|
||||
}
|
||||
} else {
|
||||
filteredDisks = append(filteredDisks, disk)
|
||||
}
|
||||
}
|
||||
return filteredDisks
|
||||
}
|
||||
|
@ -42,8 +42,7 @@ func (as *availabilitySet) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
||||
return err
|
||||
}
|
||||
|
||||
disks := make([]compute.DataDisk, len(*vm.StorageProfile.DataDisks))
|
||||
copy(disks, *vm.StorageProfile.DataDisks)
|
||||
disks := filterDetachingDisks(*vm.StorageProfile.DataDisks)
|
||||
|
||||
if isManagedDisk {
|
||||
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
|
||||
@ -117,8 +116,7 @@ func (as *availabilitySet) DetachDisk(diskName, diskURI string, nodeName types.N
|
||||
return nil, err
|
||||
}
|
||||
|
||||
disks := make([]compute.DataDisk, len(*vm.StorageProfile.DataDisks))
|
||||
copy(disks, *vm.StorageProfile.DataDisks)
|
||||
disks := filterDetachingDisks(*vm.StorageProfile.DataDisks)
|
||||
|
||||
bFoundDisk := false
|
||||
for i, disk := range disks {
|
||||
|
@ -44,8 +44,7 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
|
||||
|
||||
disks := []compute.DataDisk{}
|
||||
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
|
||||
disks = make([]compute.DataDisk, len(*vm.StorageProfile.DataDisks))
|
||||
copy(disks, *vm.StorageProfile.DataDisks)
|
||||
disks = filterDetachingDisks(*vm.StorageProfile.DataDisks)
|
||||
}
|
||||
if isManagedDisk {
|
||||
managedDisk := &compute.ManagedDiskParameters{ID: &diskURI}
|
||||
@ -123,8 +122,7 @@ func (ss *scaleSet) DetachDisk(diskName, diskURI string, nodeName types.NodeName
|
||||
|
||||
disks := []compute.DataDisk{}
|
||||
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
|
||||
disks = make([]compute.DataDisk, len(*vm.StorageProfile.DataDisks))
|
||||
copy(disks, *vm.StorageProfile.DataDisks)
|
||||
disks = filterDetachingDisks(*vm.StorageProfile.DataDisks)
|
||||
}
|
||||
bFoundDisk := false
|
||||
for i, disk := range disks {
|
||||
|
Loading…
Reference in New Issue
Block a user