diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 87d2210ea46..5446c4074f6 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -909,6 +909,24 @@ func (c *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) { addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: externalIP}) } + internalDNS, err := c.metadata.GetMetadata("local-hostname") + if err != nil || len(internalDNS) == 0 { + //TODO: It would be nice to be able to determine the reason for the failure, + // but the AWS client masks all failures with the same error description. + glog.V(2).Info("Could not determine private DNS from AWS metadata.") + } else { + addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalDNS, Address: internalDNS}) + } + + externalDNS, err := c.metadata.GetMetadata("public-hostname") + if err != nil || len(externalDNS) == 0 { + //TODO: It would be nice to be able to determine the reason for the failure, + // but the AWS client masks all failures with the same error description. + glog.V(2).Info("Could not determine public DNS from AWS metadata.") + } else { + addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalDNS, Address: externalDNS}) + } + return addresses, nil } instance, err := c.getInstanceByNodeName(name) @@ -940,6 +958,14 @@ func (c *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) { addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: ip.String()}) } + if !isNilOrEmpty(instance.PrivateDnsName) { + addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalDNS, Address: *instance.PrivateDnsName}) + } + + if !isNilOrEmpty(instance.PublicDnsName) { + addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalDNS, Address: *instance.PublicDnsName}) + } + return addresses, nil } diff --git a/pkg/cloudprovider/providers/aws/aws_test.go b/pkg/cloudprovider/providers/aws/aws_test.go index 4096a7b4141..08a65053669 100644 --- a/pkg/cloudprovider/providers/aws/aws_test.go +++ b/pkg/cloudprovider/providers/aws/aws_test.go @@ -345,6 +345,8 @@ func (self *FakeMetadata) GetMetadata(key string) (string, error) { return aws.StringValue(i.InstanceId), nil } else if key == "local-hostname" { return aws.StringValue(i.PrivateDnsName), nil + } else if key == "public-hostname" { + return aws.StringValue(i.PublicDnsName), nil } else if key == "local-ipv4" { return aws.StringValue(i.PrivateIpAddress), nil } else if key == "public-ipv4" { @@ -553,6 +555,7 @@ func TestNodeAddresses(t *testing.T) { instance0.InstanceId = aws.String("i-0") instance0.PrivateDnsName = aws.String("instance-same.ec2.internal") instance0.PrivateIpAddress = aws.String("192.168.0.1") + instance0.PublicDnsName = aws.String("instance-same.ec2.external") instance0.PublicIpAddress = aws.String("1.2.3.4") instance0.InstanceType = aws.String("c3.large") instance0.Placement = &ec2.Placement{AvailabilityZone: aws.String("us-east-1a")} @@ -603,12 +606,14 @@ func TestNodeAddresses(t *testing.T) { if err3 != nil { t.Errorf("Should not error when instance found") } - if len(addrs3) != 3 { - t.Errorf("Should return exactly 3 NodeAddresses") + if len(addrs3) != 5 { + t.Errorf("Should return exactly 5 NodeAddresses") } testHasNodeAddress(t, addrs3, v1.NodeInternalIP, "192.168.0.1") testHasNodeAddress(t, addrs3, v1.NodeLegacyHostIP, "192.168.0.1") testHasNodeAddress(t, addrs3, v1.NodeExternalIP, "1.2.3.4") + testHasNodeAddress(t, addrs3, v1.NodeExternalDNS, "instance-same.ec2.external") + testHasNodeAddress(t, addrs3, v1.NodeInternalDNS, "instance-same.ec2.internal") // Fetch from metadata aws4, fakeServices := mockInstancesResp(&instance0, []*ec2.Instance{&instance0})