Code change:
_, err := framework.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) framework.ExpectError(err, "expected error when trying to connect to cluster IP") } <del> }) ginkgo.It("should respect internalTrafficPolicy=Local Pod (hostNetwork: true) to Pod (hostNetwork: true) [Feature:ServiceInternalTrafficPolicy]", func() { // windows kube-proxy does not support this feature yet // TODO: remove this skip when windows-based proxies implement internalTrafficPolicy e2eskipper.SkipIfNodeOSDistroIs("windows") // This behavior is not supported if Kube-proxy is in "userspace" mode. // So we check the kube-proxy mode and skip this test if that's the case. if proxyMode, err := proxyMode(f); err == nil { if proxyMode == "userspace" { e2eskipper.Skipf("The test doesn't work with kube-proxy in userspace mode") } } else { framework.Logf("Couldn't detect KubeProxy mode - test failure may be expected: %v", err) } </del> <ins> ginkgo.By("Creating 2 pause hostNetwork pods that will try to connect to the webserver") pausePod2 := e2epod.NewAgnhostPod(ns, "pause-pod-2", nil, nil, nil) pausePod2.Spec.HostNetwork = true e2epod.SetNodeSelection(&pausePod2.Spec, e2epod.NodeSelection{Name: node0.Name}) </ins> <del> nodes, err := e2enode.GetBoundedReadySchedulableNodes(cs, 2) </del> <ins> pausePod2, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pausePod2, metav1.CreateOptions{}) </ins> framework.ExpectNoError(err) <del> nodeCounts := len(nodes.Items) if nodeCounts < 2 { e2eskipper.Skipf("The test requires at least two ready nodes on %s, but found %v", framework.TestContext.Provider, nodeCounts) } node0 := nodes.Items[0] node1 := nodes.Items[1] </del> <ins> framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, pausePod2.Name, f.Namespace.Name, framework.PodStartTimeout)) </ins> <del> serviceName := "svc-itp" ns := f.Namespace.Name servicePort := 80 </del> <ins> pausePod3 := e2epod.NewAgnhostPod(ns, "pause-pod-3", nil, nil, nil) pausePod3.Spec.HostNetwork = true e2epod.SetNodeSelection(&pausePod3.Spec, e2epod.NodeSelection{Name: node1.Name}) </ins> <del> ginkgo.By("creating a TCP service " + serviceName + " with type=ClusterIP and internalTrafficPolicy=Local in namespace " + ns) local := v1.ServiceInternalTrafficPolicyLocal jig := e2eservice.NewTestJig(cs, ns, serviceName) svc, err := jig.CreateTCPService(func(svc *v1.Service) { svc.Spec.Ports = []v1.ServicePort{ {Port: 80, Name: "http", Protocol: v1.ProtocolTCP, TargetPort: intstr.FromInt(80)}, } svc.Spec.InternalTrafficPolicy = &local }) framework.ExpectNoError(err) ginkgo.By("Creating 1 webserver pod to be part of the TCP service") webserverPod0 := e2epod.NewAgnhostPod(ns, "echo-hostname-0", nil, nil, nil, "netexec", "--http-port", strconv.Itoa(servicePort)) webserverPod0.Labels = jig.Labels webserverPod0.Spec.HostNetwork = true e2epod.SetNodeSelection(&webserverPod0.Spec, e2epod.NodeSelection{Name: node0.Name}) _, err = cs.CoreV1().Pods(ns).Create(context.TODO(), webserverPod0, metav1.CreateOptions{}) </del> <ins> pausePod3, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pausePod3, metav1.CreateOptions{}) </ins> framework.ExpectNoError(err) <del> framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, webserverPod0.Name, f.Namespace.Name, framework.PodStartTimeout)) validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{webserverPod0.Name: {servicePort}}) ginkgo.By("Creating 2 pause pods that will try to connect to the webservers") pausePod0 := e2epod.NewAgnhostPod(ns, "pause-pod-0", nil, nil, nil) pausePod0.Spec.HostNetwork = true e2epod.SetNodeSelection(&pausePod0.Spec, e2epod.NodeSelection{Name: node0.Name}) pausePod0, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pausePod0, metav1.CreateOptions{}) framework.ExpectNoError(err) framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, pausePod0.Name, f.Namespace.Name, framework.PodStartTimeout)) pausePod1 := e2epod.NewAgnhostPod(ns, "pause-pod-1", nil, nil, nil) pausePod1.Spec.HostNetwork = true e2epod.SetNodeSelection(&pausePod1.Spec, e2epod.NodeSelection{Name: node1.Name}) pausePod1, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pausePod1, metav1.CreateOptions{}) framework.ExpectNoError(err) framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, pausePod1.Name, f.Namespace.Name, framework.PodStartTimeout)) </del> <ins> framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(f.ClientSet, pausePod3.Name, f.Namespace.Name, framework.PodStartTimeout)) </ins> // assert 5 times that the first pause pod can connect to the Service locally and the second one errors with a timeout <del> serviceAddress := net.JoinHostPort(svc.Spec.ClusterIP, strconv.Itoa(servicePort)) </del> for i := 0; i < 5; i++ { // the first pause pod should be on the same node as the webserver, so it can connect to the local pod using clusterIP // note that the expected hostname is the node name because the backend pod is on host network <del> execHostnameTest(*pausePod0, serviceAddress, node0.Name) </del> <ins> execHostnameTest(*pausePod2, serviceAddress, node0.Name) </ins> // the second pause pod is on a different node, so it should see a connection error every time cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) <del> _, err := framework.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) </del> <ins> _, err := framework.RunHostCmd(pausePod3.Namespace, pausePod3.Name, cmd) </ins> framework.ExpectError(err, "expected error when trying to connect to cluster IP") } })

Related discussion:
text: Failed here /retest Originally posted by in This fails because the pod tries to bind port 80, that is a very demanded port, but there are two tests doing that, that increase the chance to collide
/sig network
Close when merges
/triage accepted