From c811fc58ef0914e5a004731dd9e87527e71acc81 Mon Sep 17 00:00:00 2001 From: Anish Ramasekar Date: Fri, 21 Feb 2020 09:46:38 -0800 Subject: [PATCH] check ip family for node port connectivity test --- test/e2e/framework/service/jig.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/service/jig.go b/test/e2e/framework/service/jig.go index 71b6ecb3ef6..b010f4148ba 100644 --- a/test/e2e/framework/service/jig.go +++ b/test/e2e/framework/service/jig.go @@ -764,9 +764,11 @@ func testReachabilityOverClusterIP(clusterIP string, sp v1.ServicePort, execPod return nil } -func testReachabilityOverNodePorts(nodes *v1.NodeList, sp v1.ServicePort, pod *v1.Pod) error { +func testReachabilityOverNodePorts(nodes *v1.NodeList, sp v1.ServicePort, pod *v1.Pod, clusterIP string) error { internalAddrs := e2enode.CollectAddresses(nodes, v1.NodeInternalIP) externalAddrs := e2enode.CollectAddresses(nodes, v1.NodeExternalIP) + isClusterIPV4 := net.ParseIP(clusterIP).To4() != nil + 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 @@ -774,12 +776,25 @@ func testReachabilityOverNodePorts(nodes *v1.NodeList, sp v1.ServicePort, pod *v framework.Logf("skipping testEndpointReachability() for internal adddress %s", internalAddr) continue } + isNodeInternalIPV4 := net.ParseIP(internalAddr).To4() != nil + // Check service reachability on the node internalIP which is same family + // as clusterIP + if isClusterIPV4 != isNodeInternalIPV4 { + framework.Logf("skipping testEndpointReachability() for internal adddress %s as it does not match clusterIP (%s) family", internalAddr, clusterIP) + continue + } + err := testEndpointReachability(internalAddr, sp.NodePort, sp.Protocol, pod) if err != nil { return err } } for _, externalAddr := range externalAddrs { + isNodeExternalIPV4 := net.ParseIP(externalAddr).To4() != nil + if isClusterIPV4 != isNodeExternalIPV4 { + framework.Logf("skipping testEndpointReachability() for external adddress %s as it does not match clusterIP (%s) family", externalAddr, clusterIP) + continue + } err := testEndpointReachability(externalAddr, sp.NodePort, sp.Protocol, pod) if err != nil { return err @@ -879,7 +894,7 @@ func (j *TestJig) checkNodePortServiceReachability(svc *v1.Service, pod *v1.Pod) if err != nil { return err } - err = testReachabilityOverNodePorts(nodes, servicePort, pod) + err = testReachabilityOverNodePorts(nodes, servicePort, pod, clusterIP) if err != nil { return err }