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:
Kubernetes Prow Robot 2019-08-10 04:19:14 -07:00 committed by GitHub
commit 3e962cb61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.