Merge pull request #34259 from liggitt/node-dns

Automatic merge from submit-queue (batch tested with PRs 41756, 36344, 34259, 40843, 41526)

add InternalDNS/ExternalDNS node address types

This PR adds internal/external DNS names to the types of NodeAddresses that can be reported by the kubelet.

will spawn follow up issues for cloud provider owners to include these when possible

```release-note
Nodes can now report two additional address types in their status: InternalDNS and ExternalDNS. The apiserver can use `--kubelet-preferred-address-types` to give priority to the type of address it uses to reach nodes.
```
This commit is contained in:
Kubernetes Submit Queue 2017-02-20 13:39:37 -08:00 committed by GitHub
commit 8738e36c70
5 changed files with 45 additions and 2 deletions

View File

@ -86,9 +86,17 @@ func NewServerRunOptions() *ServerRunOptions {
Port: ports.KubeletPort,
ReadOnlyPort: ports.KubeletReadOnlyPort,
PreferredAddressTypes: []string{
// --override-hostname
string(api.NodeHostName),
// internal, preferring DNS if reported
string(api.NodeInternalDNS),
string(api.NodeInternalIP),
// external, preferring DNS if reported
string(api.NodeExternalDNS),
string(api.NodeExternalIP),
string(api.NodeLegacyHostIP),
},
EnableHttps: true,

View File

@ -2732,6 +2732,8 @@ const (
NodeHostName NodeAddressType = "Hostname"
NodeExternalIP NodeAddressType = "ExternalIP"
NodeInternalIP NodeAddressType = "InternalIP"
NodeExternalDNS NodeAddressType = "ExternalDNS"
NodeInternalDNS NodeAddressType = "InternalDNS"
)
type NodeAddress struct {

View File

@ -3153,6 +3153,8 @@ const (
NodeHostName NodeAddressType = "Hostname"
NodeExternalIP NodeAddressType = "ExternalIP"
NodeInternalIP NodeAddressType = "InternalIP"
NodeExternalDNS NodeAddressType = "ExternalDNS"
NodeInternalDNS NodeAddressType = "InternalDNS"
)
// NodeAddress contains information for the node's address.

View File

@ -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
}

View File

@ -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})