From 9585658eaa90bc1b15d9a55b3d341d9a6dd919d9 Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Tue, 29 Aug 2017 11:17:43 +0200 Subject: [PATCH] implementation of GetZoneByProviderID and GetZoneByNodeName for AWS --- pkg/cloudprovider/providers/aws/aws.go | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index ad52baea296..f771ba6f582 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -1211,14 +1211,38 @@ func (c *Cloud) GetZone() (cloudprovider.Zone, error) { // This is particularly useful in external cloud providers where the kubelet // does not initialize node data. func (c *Cloud) GetZoneByProviderID(providerID string) (cloudprovider.Zone, error) { - return cloudprovider.Zone{}, errors.New("GetZoneByProviderID not implemented") + instanceID, err := kubernetesInstanceID(providerID).mapToAWSInstanceID() + if err != nil { + return cloudprovider.Zone{}, err + } + instance, err := c.getInstanceByID(string(instanceID)) + if err != nil { + return cloudprovider.Zone{}, err + } + + zone := cloudprovider.Zone{ + FailureDomain: *(instance.Placement.AvailabilityZone), + Region: c.region, + } + + return zone, nil } // GetZoneByNodeName implements Zones.GetZoneByNodeName // This is particularly useful in external cloud providers where the kubelet // does not initialize node data. func (c *Cloud) GetZoneByNodeName(nodeName types.NodeName) (cloudprovider.Zone, error) { - return cloudprovider.Zone{}, errors.New("GetZoneByNodeName not imeplemented") + instance, err := c.getInstanceByNodeName(nodeName) + if err != nil { + return cloudprovider.Zone{}, err + } + zone := cloudprovider.Zone{ + FailureDomain: *(instance.Placement.AvailabilityZone), + Region: c.region, + } + + return zone, nil + } // Abstraction around AWS Instance Types