Repository: kubernetes/kubernetes (language: go)

Issue:
--hostname-override flag on kubelet is no longer used for Addresses.Hostname value in Kubernetes 1.29
### What happened?

It looks like there was a change that first appeared in Kubernetes 1.29, where in 1.29 the `--hostname-override` flag on kubelet is no longer being used to populate the Node's Addresses.Hostname value.  Here is the relevant output from a `kubectl describe node` for a 1.28 cluster with `hostname-override=10.X.X.X`:

```
Addresses:
  InternalIP:  10.X.X.X
  ExternalIP:  52.X.X.X
  Hostname:    10.X.X.X
```

And here's the output from a 1.29 cluster with the same configuration:

```
Addresses:
  InternalIP:  10.X.X.X
  ExternalIP:  52.X.X.X
```

Here is the full `kubelet` list of parameters in case that is helpful:

`/usr/local/bin/kubelet --config=/etc/kubernetes/kubelet-config.yaml --root-dir=/var/data/kubelet --node-labels=privateVLAN=XXXXXXX,publicVLAN=XXXXXXX --cloud-provider=external --v=2 --kubeconfig=/etc/kubernetes/kubelet-kubeconfig --hostname-override=10.X.X.X --enable-controller-attach-detach=false --version=v1.28.9+IKS --runtime-cgroups=/podruntime/runtime`

This is from an IBM Cloud Kubernetes Service 1.28 and 1.29 cluster.  We do not think there was any cloud-configuration-manager or any other related change that would cause this difference.  Is it possible it is a side effect of https://github.com/kubernetes/kubernetes/pull/121028 ?

### What did you expect to happen?

I expected the behavior to be consistent between Kubernetes releases, since I didn't find any reference to this change in https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.29.md

### How can we reproduce it (as minimally and precisely as possible)?

Create an IBM Cloud Kubernetes Service cluster at 1.28 and 1.29 and see the difference

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
Client Version: v1.29.4
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.4+IKS
$ 
```

</details>


### Cloud provider

<details>

</details>


### OS version

<details>

```console
# On Linux:
root@test-coiu89n20065io30q4n0-bpvg1713759-default-00000251:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
root@test-coiu89n20065io30q4n0-bpvg1713759-default-00000251:/# uname -a
Linux test-coiu89n20065io30q4n0-bpvg1713759-default-00000251 5.4.0-176-generic #196-Ubuntu SMP Fri Mar 22 16:46:39 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
root@test-coiu89n20065io30q4n0-bpvg1713759-default-00000251:/# 

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>



Discussion / hints:
This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.

The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.


<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
yeah, it seems likely my change broke this, it should keep working as you say, let me take a look
/assign @aojea 
/sig network
/sig cloud-provider
/assign @danwinship 
/unassign 

Thanks
> I expected the behavior to be consistent between Kubernetes releases, since I didn't find any reference to this change in https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.29.md

FYI it was an unintended side effect of:

> `kubelet`, when using `--cloud-provider=external`, will now initialize the node addresses with the value of `--node-ip`, if it exists, or waits for the cloud provider to assign the addresses. (https://github.com/kubernetes/kubernetes/pull/121028, [@aojea](https://github.com/aojea))

@danwinship Do the sig cloud provider folks need to help here? We did make external cloud providers the default as of 1.29, which may have uncovered this. Let us know!
No, it's just a dumb kubelet startup bug. Well, not dumb, but easy to fix.

Fix patch:
diff --git a/pkg/kubelet/nodestatus/setters.go b/pkg/kubelet/nodestatus/setters.go
index b1fb7e8524b5a..19bb6ce729586 100644
--- a/pkg/kubelet/nodestatus/setters.go
+++ b/pkg/kubelet/nodestatus/setters.go
@@ -135,6 +135,9 @@ func NodeAddress(nodeIPs []net.IP, // typically Kubelet.nodeIPs
 			// in https://github.com/kubernetes/kubernetes/issues/120720.
 			// We are already hinting the external cloud provider via the annotation AnnotationAlphaProvidedIPAddr.
 			if !nodeIPSpecified {
+				node.Status.Addresses = []v1.NodeAddress{
+					{Type: v1.NodeHostName, Address: hostname},
+				}
 				return nil
 			}
 		}


Test patch:
diff --git a/pkg/kubelet/nodestatus/setters_test.go b/pkg/kubelet/nodestatus/setters_test.go
index 282d20093b46b..01989cb928728 100644
--- a/pkg/kubelet/nodestatus/setters_test.go
+++ b/pkg/kubelet/nodestatus/setters_test.go
@@ -238,15 +238,19 @@ func TestNodeAddress(t *testing.T) {
 			nodeIP:            netutils.ParseIPSloppy("::"),
 			nodeAddresses:     []v1.NodeAddress{},
 			cloudProviderType: cloudProviderExternal,
-			expectedAddresses: []v1.NodeAddress{},
-			shouldError:       false,
+			expectedAddresses: []v1.NodeAddress{
+				{Type: v1.NodeHostName, Address: testKubeletHostname},
+			},
+			shouldError: false,
 		},
 		{
 			name:              "cloud provider is external and no nodeIP",
 			nodeAddresses:     []v1.NodeAddress{},
 			cloudProviderType: cloudProviderExternal,
-			expectedAddresses: []v1.NodeAddress{},
-			shouldError:       false,
+			expectedAddresses: []v1.NodeAddress{
+				{Type: v1.NodeHostName, Address: testKubeletHostname},
+			},
+			shouldError: false,
 		},
 		{
 			name: "cloud doesn't report hostname, no override, detected hostname mismatch",