From a29fabe20dcdecb15c7bf469160f1849f71a07c8 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Wed, 25 Jul 2018 18:16:21 +0800 Subject: [PATCH] Get availability zone for VirtualMachineScaleSetVM --- .../providers/azure/azure_vmss.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/cloudprovider/providers/azure/azure_vmss.go b/pkg/cloudprovider/providers/azure/azure_vmss.go index 463ff33e134..04e62e696e9 100644 --- a/pkg/cloudprovider/providers/azure/azure_vmss.go +++ b/pkg/cloudprovider/providers/azure/azure_vmss.go @@ -213,9 +213,6 @@ func (ss *scaleSet) GetInstanceTypeByNodeName(name string) (string, error) { // GetZoneByNodeName gets availability zone for the specified node. If the node is not running // with availability zone, then it returns fault domain. -// TODO(feiskyer): Add availability zone support of VirtualMachineScaleSetVM -// after it is released in Azure Go SDK. -// Refer https://github.com/Azure/azure-sdk-for-go/pull/2224. func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) { managedByAS, err := ss.isNodeManagedByAvailabilitySet(name) if err != nil { @@ -232,14 +229,25 @@ func (ss *scaleSet) GetZoneByNodeName(name string) (cloudprovider.Zone, error) { return cloudprovider.Zone{}, err } - if vm.InstanceView != nil && vm.InstanceView.PlatformFaultDomain != nil { - return cloudprovider.Zone{ - FailureDomain: strconv.Itoa(int(*vm.InstanceView.PlatformFaultDomain)), - Region: *vm.Location, - }, nil + var failureDomain string + if vm.Zones != nil && len(*vm.Zones) > 0 { + // Get availability zone for the node. + zones := *vm.Zones + zoneID, err := strconv.Atoi(zones[0]) + if err != nil { + return cloudprovider.Zone{}, fmt.Errorf("failed to parse zone %q: %v", zones, err) + } + + failureDomain = ss.makeZone(zoneID) + } else if vm.InstanceView != nil && vm.InstanceView.PlatformFaultDomain != nil { + // Availability zone is not used for the node, falling back to fault domain. + failureDomain = strconv.Itoa(int(*vm.InstanceView.PlatformFaultDomain)) } - return cloudprovider.Zone{}, nil + return cloudprovider.Zone{ + FailureDomain: failureDomain, + Region: *vm.Location, + }, nil } // GetPrimaryVMSetName returns the VM set name depending on the configured vmType.