Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic for GetZoneByNodeName on Azure Stack #8755

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/provider/azure_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ func (as *availabilitySet) GetZoneByNodeName(ctx context.Context, name string) (
failureDomain = as.makeZone(ptr.Deref(vm.Location, ""), zoneID)
} else {
// Availability zone is not used for the node, falling back to fault domain.
failureDomain = strconv.Itoa(int(ptr.Deref(vm.Properties.InstanceView.PlatformFaultDomain, 0)))
if prop := vm.Properties; prop == nil || prop.InstanceView == nil {
failureDomain = "0"
} else {
failureDomain = strconv.Itoa(int(ptr.Deref(vm.Properties.InstanceView.PlatformFaultDomain, 0)))
}
}

zone := cloudprovider.Zone{
Expand Down
16 changes: 16 additions & 0 deletions pkg/provider/azure_standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,22 @@ func TestGetStandardVMZoneByNodeName(t *testing.T) {
},
expectedErrMsg: fmt.Errorf("failed to parse zone %q: strconv.Atoi: parsing %q: invalid syntax", []string{"a"}, "a"),
},
{
name: "GetZoneByNodeName should set failuredomain to 0 if no zones are found",
nodeName: "vm5",
vm: &armcompute.VirtualMachine{
Name: ptr.To("vm5"),
Location: ptr.To("HybridEnvironment"),
Zones: []*string{},
Properties: &armcompute.VirtualMachineProperties{
InstanceView: nil, // can be nil on Azure Stack
},
},
expectedZone: cloudprovider.Zone{
FailureDomain: "0",
Region: "hybridenvironment",
},
},
}
for _, test := range testcases {
mockVMClient := cloud.ComputeClientFactory.GetVirtualMachineClient().(*mock_virtualmachineclient.MockInterface)
Expand Down