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
```
pull/8/head
Kubernetes Submit Queue 2018-04-28 03:47:09 -07:00 committed by GitHub
commit 81478b804e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -34,7 +34,10 @@ func (ss *scaleSet) AttachDisk(isManagedDisk bool, diskName, diskURI string, nod
return err
}
disks := *vm.StorageProfile.DataDisks
disks := []compute.DataDisk{}
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
disks = *vm.StorageProfile.DataDisks
}
if isManagedDisk {
disks = append(disks,
compute.DataDisk{
@ -95,7 +98,10 @@ func (ss *scaleSet) DetachDiskByName(diskName, diskURI string, nodeName types.No
return err
}
disks := *vm.StorageProfile.DataDisks
disks := []compute.DataDisk{}
if vm.StorageProfile != nil && vm.StorageProfile.DataDisks != nil {
disks = *vm.StorageProfile.DataDisks
}
bFoundDisk := false
for i, disk := range disks {
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
return nil, err
}
if vm.StorageProfile.DataDisks == nil {
if vm.StorageProfile == nil || vm.StorageProfile.DataDisks == nil {
return nil, nil
}