From 715627d95e080d87aacb64823f94edd2faa7100a Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 8 Aug 2019 11:03:58 +0200 Subject: [PATCH] Fix node port service reachability test for nodes running on localhost If a node's internal address points to 127.0.0.1, then we skip the node port reachability test. Signed-off-by: Sascha Grunert --- test/e2e/framework/service/jig.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/e2e/framework/service/jig.go b/test/e2e/framework/service/jig.go index eff844cc07f..cdbae8db0e4 100644 --- a/test/e2e/framework/service/jig.go +++ b/test/e2e/framework/service/jig.go @@ -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.