Skip to content

Commit

Permalink
Service E2Es: ensure pods can communicate using src port equal to nod…
Browse files Browse the repository at this point in the history
…e port

Signed-off-by: Martin Kennelly <mkennell@redhat.com>
  • Loading branch information
martinkennelly committed Apr 11, 2024
1 parent 26bd3a7 commit 34b1a4b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
e2erc "k8s.io/kubernetes/test/e2e/framework/rc"
e2eservice "k8s.io/kubernetes/test/e2e/framework/service"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
testutils "k8s.io/kubernetes/test/utils"
)

Expand Down Expand Up @@ -72,6 +73,36 @@ var _ = ginkgo.Describe("Services", func() {
udpPort := int32(rand.Intn(1000) + 10000)
udpPortS := fmt.Sprintf("%d", udpPort)

ginkgo.It("Allow connection to an external IP using a source port that is equal to a node port", func() {
const (
nodePort = 31990
connTimeout = "2"
dstIPv4 = "1.1.1.1"
dstPort = "80"
)
if IsIPv6Cluster(f.ClientSet) {
e2eskipper.Skipf("Test requires IPv4 or IPv4 primary dualstack cluster")
}
ginkgo.By("create node port service")
jig := e2eservice.NewTestJig(cs, f.Namespace.Name, serviceName)
_, err := jig.CreateTCPService(context.TODO(), func(svc *v1.Service) {
svc.Spec.Type = v1.ServiceTypeNodePort
svc.Spec.Ports[0].NodePort = nodePort
})
framework.ExpectNoError(err, "failed to create TCP node port service")
ginkgo.By("create pod selected by node port service")
serverPod := e2epod.NewAgnhostPod(f.Namespace.Name, "svc-backend", nil, nil, nil)
serverPod.Labels = jig.Labels
e2epod.NewPodClient(f).CreateSync(context.TODO(), serverPod)
ginkgo.By("create pod which will connect externally")
clientPod := e2epod.NewAgnhostPod(f.Namespace.Name, "client-for-external", nil, nil, nil)
e2epod.NewPodClient(f).CreateSync(context.TODO(), clientPod)
ginkgo.By("connect externally pinning the source port to equal the node port")
_, err = e2ekubectl.RunKubectl(clientPod.Namespace, "exec", clientPod.Name, "--", "nc",
"-p", strconv.Itoa(nodePort), "-z", "-w", connTimeout, dstIPv4, dstPort)
framework.ExpectNoError(err, "expected connection to succeed using source port identical to node port")
})

ginkgo.It("Creates a host-network service, and ensures that host-network pods can connect to it", func() {
namespace := f.Namespace.Name
jig := e2eservice.NewTestJig(cs, namespace, serviceName)
Expand Down

0 comments on commit 34b1a4b

Please sign in to comment.