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 8d8ec40
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ 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"
dstIP = "1.1.1.1"
dstPort = "80"
)
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, dstIP, 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 8d8ec40

Please sign in to comment.