From 144bd102c0353aa5d2006a7a1b708ce514636137 Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Tue, 29 Aug 2017 15:40:44 +0200 Subject: [PATCH] implementation of GetZoneByProviderID and GetZoneByNodeName for azure --- .../providers/azure/azure_zones.go | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/cloudprovider/providers/azure/azure_zones.go b/pkg/cloudprovider/providers/azure/azure_zones.go index 3d993d414c6..2f9d58decf6 100644 --- a/pkg/cloudprovider/providers/azure/azure_zones.go +++ b/pkg/cloudprovider/providers/azure/azure_zones.go @@ -18,14 +18,16 @@ package azure import ( "encoding/json" - "errors" "io" "io/ioutil" "net/http" + "strconv" "sync" "k8s.io/apimachinery/pkg/types" "k8s.io/kubernetes/pkg/cloudprovider" + + "github.com/Azure/azure-sdk-for-go/arm/compute" ) const instanceInfoURL = "http://169.254.169.254/metadata/v1/InstanceInfo" @@ -61,14 +63,31 @@ func (az *Cloud) GetZone() (cloudprovider.Zone, error) { // This is particularly useful in external cloud providers where the kubelet // does not initialize node data. func (az *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) { - return cloudprovider.Zone{}, errors.New("GetZoneByProviderID not implemented") + nodeName, err := splitProviderID(providerID) + if err != nil { + return cloudprovider.Zone{}, err + } + return az.GetZoneByNodeName(nodeName) } // GetZoneByNodeName implements Zones.GetZoneByNodeName // This is particularly useful in external cloud providers where the kubelet // does not initialize node data. func (az *Cloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) { - return cloudprovider.Zone{}, errors.New("GetZoneByNodeName not imeplemented") + + vm, err := az.VirtualMachinesClient.Get(az.ResourceGroup, string(nodeName), compute.InstanceView) + + if err != nil { + return cloudprovider.Zone{}, err + } + + failureDomain := strconv.Itoa(int(*vm.VirtualMachineProperties.InstanceView.PlatformFaultDomain)) + + zone := cloudprovider.Zone{ + FailureDomain: failureDomain, + Region: *(vm.Location), + } + return zone, nil } func fetchFaultDomain() (*string, error) {