mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Populate NodeHostName status.
This commit is contained in:
parent
482475e378
commit
b7880e7cd8
@ -358,9 +358,8 @@ func (kl *Kubelet) recordNodeStatusEvent(eventtype, event string) {
|
||||
kl.recorder.Eventf(kl.nodeRef, eventtype, event, "Node %s status is now: %s", kl.nodeName, event)
|
||||
}
|
||||
|
||||
// Set IP addresses for the node.
|
||||
// Set IP and hostname addresses for the node.
|
||||
func (kl *Kubelet) setNodeAddress(node *api.Node) error {
|
||||
|
||||
if kl.nodeIP != nil {
|
||||
if err := kl.validateNodeIP(); err != nil {
|
||||
return fmt.Errorf("failed to validate nodeIP: %v", err)
|
||||
@ -381,20 +380,20 @@ func (kl *Kubelet) setNodeAddress(node *api.Node) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get node address from cloud provider: %v", err)
|
||||
}
|
||||
|
||||
if kl.nodeIP != nil {
|
||||
for _, nodeAddress := range nodeAddresses {
|
||||
if nodeAddress.Address == kl.nodeIP.String() {
|
||||
node.Status.Addresses = []api.NodeAddress{
|
||||
{Type: nodeAddress.Type, Address: nodeAddress.Address},
|
||||
{Type: api.NodeHostName, Address: kl.GetHostname()},
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("failed to get node address from cloud provider that matches ip: %v", kl.nodeIP)
|
||||
}
|
||||
|
||||
node.Status.Addresses = nodeAddresses
|
||||
hostnameAddress := api.NodeAddress{Type: api.NodeHostName, Address: kl.GetHostname()}
|
||||
node.Status.Addresses = append(nodeAddresses, hostnameAddress)
|
||||
} else {
|
||||
var ipAddr net.IP
|
||||
var err error
|
||||
@ -429,6 +428,7 @@ func (kl *Kubelet) setNodeAddress(node *api.Node) error {
|
||||
node.Status.Addresses = []api.NodeAddress{
|
||||
{Type: api.NodeLegacyHostIP, Address: ipAddr.String()},
|
||||
{Type: api.NodeInternalIP, Address: ipAddr.String()},
|
||||
{Type: api.NodeHostName, Address: kl.GetHostname()},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +193,7 @@ func TestUpdateNewNodeStatus(t *testing.T) {
|
||||
Addresses: []api.NodeAddress{
|
||||
{Type: api.NodeLegacyHostIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeHostName, Address: testKubeletHostname},
|
||||
},
|
||||
Images: expectedImageList,
|
||||
},
|
||||
@ -472,6 +473,7 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
|
||||
Addresses: []api.NodeAddress{
|
||||
{Type: api.NodeLegacyHostIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeHostName, Address: testKubeletHostname},
|
||||
},
|
||||
// images will be sorted from max to min in node status.
|
||||
Images: []api.ContainerImage{
|
||||
@ -777,6 +779,7 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) {
|
||||
Addresses: []api.NodeAddress{
|
||||
{Type: api.NodeLegacyHostIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeInternalIP, Address: "127.0.0.1"},
|
||||
{Type: api.NodeHostName, Address: testKubeletHostname},
|
||||
},
|
||||
Images: []api.ContainerImage{
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user