@@ -264,8 +264,30 @@ func (config *NetworkingTestConfig) diagnoseMissingEndpoints(foundEndpoints sets
264
264
func (config * NetworkingTestConfig ) EndpointHostnames () sets.String {
265
265
expectedEps := sets .NewString ()
266
266
for _ , p := range config .EndpointPods {
267
+
267
268
if config .EndpointsHostNetwork {
268
- expectedEps .Insert (p .Spec .NodeSelector ["kubernetes.io/hostname" ])
269
+ // Hostname behavior for hostNetwork pods is not well defined and when
270
+ // using the flag hostname-override in the kubelet, the node reported
271
+ // hostname on host network pods will not match the node's hostanme.
272
+ // It seems that the node.status.addresses hostname value is the only
273
+ // one that matches the value returned by os.Hostname
274
+ // used by the agnhost web handler, so we'll use that value.
275
+ // If by any circumstances the node does not provide that hostnae address
276
+ // we use the value of the node name.
277
+ // xref: https://issues.k8s.io/126087
278
+ hostname := p .Spec .NodeSelector ["kubernetes.io/hostname" ]
279
+ for _ , n := range config .Nodes {
280
+ if n .Name == p .Spec .NodeSelector ["kubernetes.io/hostname" ] {
281
+ for _ , address := range n .Status .Addresses {
282
+ if address .Type == v1 .NodeHostName {
283
+ hostname = address .Address
284
+ break
285
+ }
286
+ }
287
+ break
288
+ }
289
+ }
290
+ expectedEps .Insert (hostname )
269
291
} else {
270
292
expectedEps .Insert (p .Name )
271
293
}
0 commit comments