Unverified Commit 81478b80 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #63275 from feiskyer/vmss-disk

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix panic for attaching AzureDisk to vmss nodes **What this PR does / why we need it**: Azure vmss virtual machine's data disks may be nil (while Azure virtual machine doesn't have the issue) so it will panic controller-manager when attaching new disks. This PR fixes the issue by adding a check. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: Should be cherry picked to v1.10. **Release note**: ```release-note Fix panic for attaching AzureDisk to vmss nodes ```
parents 24bc761a fd559ee1
...@@ -34,7 +34,10 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod ...@@ -34,7 +34,10 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
return err return err
} }
disks := *vm.StorageProfile.DataDisks disks := []compute.DataDisk{}
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
disks = *vm.StorageProfile.DataDisks
}
if isManagedDisk { if isManagedDisk {
disks = append(disks, disks = append(disks,
compute.DataDisk{ compute.DataDisk{
...@@ -95,7 +98,10 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No ...@@ -95,7 +98,10 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
return err return err
} }
disks := *vm.StorageProfile.DataDisks disks := []compute.DataDisk{}
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
disks = *vm.StorageProfile.DataDisks
}
bFoundDisk := false bFoundDisk := false
for i, disk := range disks { for i, disk := range disks {
if disk.Lun != nil && (disk.Name != nil && diskName != "" && *disk.Name == diskName) || if disk.Lun != nil && (disk.Name != nil && diskName != "" && *disk.Name == diskName) ||
...@@ -144,7 +150,7 @@ func (ss *scaleSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, e ...@@ -144,7 +150,7 @@ func (ss *scaleSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, e
return nil, err return nil, err
} }
if vm.StorageProfile.DataDisks == nil { if vm.StorageProfile == nil || vm.StorageProfile.DataDisks == nil {
return nil, nil return nil, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment