Skip to content

Commit 95731ae

Browse files
Fix panic for GetZoneByNodeName on Azure Stack (#8755)
* Fix panic for GetZoneByNodeName on Azure Stack Azure Stack does not support the API Version, 2020-12-01, for PlatformFaultDomain, and therefore panics when we run the cloud provider on Azure Stack. This avoids the panic, but we cannot get the correct PlatformFaultDomain (which may not be an issue). * Add GetZoneByNodeName test for VM with no zones
1 parent f620c09 commit 95731ae

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/provider/azure_standard.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ func (as *availabilitySet) GetZoneByNodeName(ctx context.Context, name string) (
580580
failureDomain = as.makeZone(ptr.Deref(vm.Location, ""), zoneID)
581581
} else {
582582
// Availability zone is not used for the node, falling back to fault domain.
583-
failureDomain = strconv.Itoa(int(ptr.Deref(vm.Properties.InstanceView.PlatformFaultDomain, 0)))
583+
if prop := vm.Properties; prop == nil || prop.InstanceView == nil {
584+
failureDomain = "0"
585+
} else {
586+
failureDomain = strconv.Itoa(int(ptr.Deref(vm.Properties.InstanceView.PlatformFaultDomain, 0)))
587+
}
584588
}
585589

586590
zone := cloudprovider.Zone{

pkg/provider/azure_standard_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,22 @@ func TestGetStandardVMZoneByNodeName(t *testing.T) {
11921192
},
11931193
expectedErrMsg: fmt.Errorf("failed to parse zone %q: strconv.Atoi: parsing %q: invalid syntax", []string{"a"}, "a"),
11941194
},
1195+
{
1196+
name: "GetZoneByNodeName should set failuredomain to 0 if no zones are found",
1197+
nodeName: "vm5",
1198+
vm: &armcompute.VirtualMachine{
1199+
Name: ptr.To("vm5"),
1200+
Location: ptr.To("HybridEnvironment"),
1201+
Zones: []*string{},
1202+
Properties: &armcompute.VirtualMachineProperties{
1203+
InstanceView: nil, // can be nil on Azure Stack
1204+
},
1205+
},
1206+
expectedZone: cloudprovider.Zone{
1207+
FailureDomain: "0",
1208+
Region: "hybridenvironment",
1209+
},
1210+
},
11951211
}
11961212
for _, test := range testcases {
11971213
mockVMClient := cloud.ComputeClientFactory.GetVirtualMachineClient().(*mock_virtualmachineclient.MockInterface)

0 commit comments

Comments
 (0)