Skip to content

Commit

Permalink
Merge pull request #51528 from yastij/azure-zone-byProviderID-nodeName
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 52047, 52063, 51528)

implementation of GetZoneByProviderID and GetZoneByNodeName for azure

This is part of the #50926 effort

cc @luxas 

**Release note**:

```release-note
None
```
  • Loading branch information
Kubernetes Submit Queue authored Sep 8, 2017
2 parents d6df4a5 + 144bd10 commit a5b3e50
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/cloudprovider/providers/azure/azure_zones.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a5b3e50

Please sign in to comment.