Skip to content

Commit 2ad04a0

Browse files
authored
Merge pull request kubernetes#126088 from aojea/e2e_hostname_hostnetwork
use node.status.addresses to obtain hostnetwork pods hostnames
2 parents 8182305 + 93736f2 commit 2ad04a0

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/e2e/framework/network/utils.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,30 @@ func (config *NetworkingTestConfig) diagnoseMissingEndpoints(foundEndpoints sets
264264
func (config *NetworkingTestConfig) EndpointHostnames() sets.String {
265265
expectedEps := sets.NewString()
266266
for _, p := range config.EndpointPods {
267+
267268
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)
269291
} else {
270292
expectedEps.Insert(p.Name)
271293
}

0 commit comments

Comments
 (0)