Let CloudProvider return list of NodeAddress, not just one net.IP

This lets cloud providers populate the NodeAddress array
This commit is contained in:
Justin Santa Barbara
2015-03-11 16:37:11 -07:00
parent 7d53425bbc
commit bc16d83a51
14 changed files with 54 additions and 46 deletions

View File

@@ -188,8 +188,8 @@ func (aws *AWSCloud) Zones() (cloudprovider.Zones, bool) {
return aws, true
}
// IPAddress is an implementation of Instances.IPAddress.
func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
// NodeAddresses is an implementation of Instances.NodeAddresses.
func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) {
inst, err := aws.getInstancesByDnsName(name)
if err != nil {
return nil, err
@@ -198,7 +198,8 @@ func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
if ip == nil {
return nil, fmt.Errorf("invalid network IP: %s", inst.PrivateIpAddress)
}
return ip, nil
return []api.NodeAddress{{Type: api.NodeLegacyHostIP, Address: ip.String()}}, nil
}
// ExternalID returns the cloud provider ID of the specified instance.

View File

@@ -168,23 +168,26 @@ func TestIPAddress(t *testing.T) {
instances[1].State.Name = "running"
aws1 := mockInstancesResp([]ec2.Instance{})
_, err1 := aws1.IPAddress("instance")
_, err1 := aws1.NodeAddresses("instance")
if err1 == nil {
t.Errorf("Should error when no instance found")
}
aws2 := mockInstancesResp(instances)
_, err2 := aws2.IPAddress("instance1")
_, err2 := aws2.NodeAddresses("instance1")
if err2 == nil {
t.Errorf("Should error when multiple instances found")
}
aws3 := mockInstancesResp(instances[0:1])
ip3, err3 := aws3.IPAddress("instance1")
addrs3, err3 := aws3.NodeAddresses("instance1")
if err3 != nil {
t.Errorf("Should not error when instance found")
}
if e, a := instances[0].PrivateIpAddress, ip3.String(); e != a {
if len(addrs3) != 1 {
t.Errorf("Should return exactly one NodeAddress")
}
if e, a := instances[0].PrivateIpAddress, addrs3[0].Address; e != a {
t.Errorf("Expected %v, got %v", e, a)
}
}