mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	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:
		@@ -86,9 +86,17 @@ func NewServerRunOptions() *ServerRunOptions {
 | 
				
			|||||||
			Port:         ports.KubeletPort,
 | 
								Port:         ports.KubeletPort,
 | 
				
			||||||
			ReadOnlyPort: ports.KubeletReadOnlyPort,
 | 
								ReadOnlyPort: ports.KubeletReadOnlyPort,
 | 
				
			||||||
			PreferredAddressTypes: []string{
 | 
								PreferredAddressTypes: []string{
 | 
				
			||||||
 | 
									// --override-hostname
 | 
				
			||||||
				string(api.NodeHostName),
 | 
									string(api.NodeHostName),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// internal, preferring DNS if reported
 | 
				
			||||||
 | 
									string(api.NodeInternalDNS),
 | 
				
			||||||
				string(api.NodeInternalIP),
 | 
									string(api.NodeInternalIP),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// external, preferring DNS if reported
 | 
				
			||||||
 | 
									string(api.NodeExternalDNS),
 | 
				
			||||||
				string(api.NodeExternalIP),
 | 
									string(api.NodeExternalIP),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				string(api.NodeLegacyHostIP),
 | 
									string(api.NodeLegacyHostIP),
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			EnableHttps: true,
 | 
								EnableHttps: true,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2732,6 +2732,8 @@ const (
 | 
				
			|||||||
	NodeHostName     NodeAddressType = "Hostname"
 | 
						NodeHostName     NodeAddressType = "Hostname"
 | 
				
			||||||
	NodeExternalIP   NodeAddressType = "ExternalIP"
 | 
						NodeExternalIP   NodeAddressType = "ExternalIP"
 | 
				
			||||||
	NodeInternalIP   NodeAddressType = "InternalIP"
 | 
						NodeInternalIP   NodeAddressType = "InternalIP"
 | 
				
			||||||
 | 
						NodeExternalDNS  NodeAddressType = "ExternalDNS"
 | 
				
			||||||
 | 
						NodeInternalDNS  NodeAddressType = "InternalDNS"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NodeAddress struct {
 | 
					type NodeAddress struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3153,6 +3153,8 @@ const (
 | 
				
			|||||||
	NodeHostName     NodeAddressType = "Hostname"
 | 
						NodeHostName     NodeAddressType = "Hostname"
 | 
				
			||||||
	NodeExternalIP   NodeAddressType = "ExternalIP"
 | 
						NodeExternalIP   NodeAddressType = "ExternalIP"
 | 
				
			||||||
	NodeInternalIP   NodeAddressType = "InternalIP"
 | 
						NodeInternalIP   NodeAddressType = "InternalIP"
 | 
				
			||||||
 | 
						NodeExternalDNS  NodeAddressType = "ExternalDNS"
 | 
				
			||||||
 | 
						NodeInternalDNS  NodeAddressType = "InternalDNS"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NodeAddress contains information for the node's address.
 | 
					// NodeAddress contains information for the node's address.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -909,6 +909,24 @@ func (c *Cloud) NodeAddresses(name types.NodeName) ([]v1.NodeAddress, error) {
 | 
				
			|||||||
			addresses = append(addresses, v1.NodeAddress{Type: v1.NodeExternalIP, Address: externalIP})
 | 
								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
 | 
							return addresses, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	instance, err := c.getInstanceByNodeName(name)
 | 
						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()})
 | 
							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
 | 
						return addresses, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -345,6 +345,8 @@ func (self *FakeMetadata) GetMetadata(key string) (string, error) {
 | 
				
			|||||||
		return aws.StringValue(i.InstanceId), nil
 | 
							return aws.StringValue(i.InstanceId), nil
 | 
				
			||||||
	} else if key == "local-hostname" {
 | 
						} else if key == "local-hostname" {
 | 
				
			||||||
		return aws.StringValue(i.PrivateDnsName), nil
 | 
							return aws.StringValue(i.PrivateDnsName), nil
 | 
				
			||||||
 | 
						} else if key == "public-hostname" {
 | 
				
			||||||
 | 
							return aws.StringValue(i.PublicDnsName), nil
 | 
				
			||||||
	} else if key == "local-ipv4" {
 | 
						} else if key == "local-ipv4" {
 | 
				
			||||||
		return aws.StringValue(i.PrivateIpAddress), nil
 | 
							return aws.StringValue(i.PrivateIpAddress), nil
 | 
				
			||||||
	} else if key == "public-ipv4" {
 | 
						} else if key == "public-ipv4" {
 | 
				
			||||||
@@ -553,6 +555,7 @@ func TestNodeAddresses(t *testing.T) {
 | 
				
			|||||||
	instance0.InstanceId = aws.String("i-0")
 | 
						instance0.InstanceId = aws.String("i-0")
 | 
				
			||||||
	instance0.PrivateDnsName = aws.String("instance-same.ec2.internal")
 | 
						instance0.PrivateDnsName = aws.String("instance-same.ec2.internal")
 | 
				
			||||||
	instance0.PrivateIpAddress = aws.String("192.168.0.1")
 | 
						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.PublicIpAddress = aws.String("1.2.3.4")
 | 
				
			||||||
	instance0.InstanceType = aws.String("c3.large")
 | 
						instance0.InstanceType = aws.String("c3.large")
 | 
				
			||||||
	instance0.Placement = &ec2.Placement{AvailabilityZone: aws.String("us-east-1a")}
 | 
						instance0.Placement = &ec2.Placement{AvailabilityZone: aws.String("us-east-1a")}
 | 
				
			||||||
@@ -603,12 +606,14 @@ func TestNodeAddresses(t *testing.T) {
 | 
				
			|||||||
	if err3 != nil {
 | 
						if err3 != nil {
 | 
				
			||||||
		t.Errorf("Should not error when instance found")
 | 
							t.Errorf("Should not error when instance found")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(addrs3) != 3 {
 | 
						if len(addrs3) != 5 {
 | 
				
			||||||
		t.Errorf("Should return exactly 3 NodeAddresses")
 | 
							t.Errorf("Should return exactly 5 NodeAddresses")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	testHasNodeAddress(t, addrs3, v1.NodeInternalIP, "192.168.0.1")
 | 
						testHasNodeAddress(t, addrs3, v1.NodeInternalIP, "192.168.0.1")
 | 
				
			||||||
	testHasNodeAddress(t, addrs3, v1.NodeLegacyHostIP, "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.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
 | 
						// Fetch from metadata
 | 
				
			||||||
	aws4, fakeServices := mockInstancesResp(&instance0, []*ec2.Instance{&instance0})
 | 
						aws4, fakeServices := mockInstancesResp(&instance0, []*ec2.Instance{&instance0})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user