mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #51528 from yastij/azure-zone-byProviderID-nodeName
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 ```
This commit is contained in:
commit
a5b3e50eac
@ -18,14 +18,16 @@ package azure
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/cloudprovider"
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
||||||
|
|
||||||
|
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
||||||
)
|
)
|
||||||
|
|
||||||
const instanceInfoURL = "http://169.254.169.254/metadata/v1/InstanceInfo"
|
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
|
// This is particularly useful in external cloud providers where the kubelet
|
||||||
// does not initialize node data.
|
// does not initialize node data.
|
||||||
func (az *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) {
|
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
|
// GetZoneByNodeName implements Zones.GetZoneByNodeName
|
||||||
// This is particularly useful in external cloud providers where the kubelet
|
// This is particularly useful in external cloud providers where the kubelet
|
||||||
// does not initialize node data.
|
// does not initialize node data.
|
||||||
func (az *Cloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) {
|
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) {
|
func fetchFaultDomain() (*string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user