mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #81157 from openSUSE/localhost-nodeport-e2e-fix
[e2e] Fix node port service reachability test for nodes running on localhost
This commit is contained in:
commit
3e962cb61a
@ -769,10 +769,17 @@ func testReachabilityOverClusterIP(clusterIP string, sp v1.ServicePort, execPod
|
||||
testEndpointReachability(clusterIP, sp.Port, sp.Protocol, execPod)
|
||||
}
|
||||
}
|
||||
|
||||
func testReachabilityOverNodePorts(nodes *v1.NodeList, sp v1.ServicePort, pod *v1.Pod) {
|
||||
internalAddrs := e2enode.CollectAddresses(nodes, v1.NodeInternalIP)
|
||||
externalAddrs := e2enode.CollectAddresses(nodes, v1.NodeExternalIP)
|
||||
for _, internalAddr := range internalAddrs {
|
||||
// If the node's internal address points to localhost, then we are not
|
||||
// able to test the service reachability via that address
|
||||
if isInvalidOrLocalhostAddress(internalAddr) {
|
||||
e2elog.Logf("skipping testEndpointReachability() for internal adddress %s", internalAddr)
|
||||
continue
|
||||
}
|
||||
testEndpointReachability(internalAddr, sp.NodePort, sp.Protocol, pod)
|
||||
}
|
||||
for _, externalAddr := range externalAddrs {
|
||||
@ -780,6 +787,16 @@ func testReachabilityOverNodePorts(nodes *v1.NodeList, sp v1.ServicePort, pod *v
|
||||
}
|
||||
}
|
||||
|
||||
// isInvalidOrLocalhostAddress returns `true` if the provided `ip` is either not
|
||||
// parsable or the loopback address. Otherwise it will return `false`.
|
||||
func isInvalidOrLocalhostAddress(ip string) bool {
|
||||
parsedIP := net.ParseIP(ip)
|
||||
if parsedIP == nil || parsedIP.IsLoopback() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// testEndpointReachability tests reachability to endpoints (i.e. IP, ServiceName) and ports. Test request is initiated from specified execPod.
|
||||
// TCP and UDP protocol based service are supported at this moment
|
||||
// TODO: add support to test SCTP Protocol based services.
|
||||
|
Loading…
Reference in New Issue
Block a user