Skip to content

Commit

Permalink
test(e2e): test multiple connections both with and without limit
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont committed Aug 8, 2022
1 parent f4598ae commit 11389f9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 29 deletions.
94 changes: 65 additions & 29 deletions test/e2e_env/kubernetes/gateway/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ func Resources() {
waitingClientNamespace := "gateway-resources-client-wait"
curlingClientNamespace := "gateway-resources-client-curl"

meshGatewayWithoutLimit := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
metadata:
name: %s
mesh: %s
spec:
selectors:
- match:
kuma.io/service: %s
conf:
listeners:
- port: 8080
protocol: HTTP
`, gatewayName, meshName, gatewayName)

meshGatewayWithLimit := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: MeshGateway
Expand Down Expand Up @@ -69,7 +85,7 @@ spec:
Install(Namespace(curlingClientNamespace)).
Install(DemoClientK8s(meshName, waitingClientNamespace)).
Install(DemoClientK8s(meshName, curlingClientNamespace)).
Install(YamlK8s(meshGatewayWithLimit)).
Install(YamlK8s(meshGatewayWithoutLimit)).
Install(YamlK8s(MkGatewayInstance(gatewayName, namespace, meshName))).
Install(YamlK8s(httpRoute)).
Install(testserver.Install(
Expand All @@ -89,11 +105,35 @@ spec:
Expect(env.Cluster.DeleteMesh(meshName)).To(Succeed())
})

Specify("connection limit is respected", func() {
gatewayHost := fmt.Sprintf("%s.%s", gatewayName, namespace)
target := fmt.Sprintf("http://%s:8080", gatewayHost)
gatewayHost := fmt.Sprintf("%s.%s", gatewayName, namespace)
target := fmt.Sprintf("http://%s:8080", gatewayHost)

keepConnectionOpen := func() {
// Open TCP connections to the gateway
defer GinkgoRecover()

By("allowing 1 connection")
demoClientPod, err := PodNameOfApp(env.Cluster, "demo-client", waitingClientNamespace)
Expect(err).ToNot(HaveOccurred())

cmd := []string{"telnet", gatewayHost, "8080"}
// We pass in a stdin that blocks so that telnet will keep the
// connection open
_, _, _ = env.Cluster.ExecWithOptions(ExecOptions{
Command: cmd,
Namespace: waitingClientNamespace,
PodName: demoClientPod,
ContainerName: "demo-client",
Stdin: &BlockingReader{},
CaptureStdout: true,
CaptureStderr: true,
PreserveWhitespace: false,
Retries: DefaultRetries,
Timeout: DefaultTimeout,
})
}

Specify("connection limit is respected", func() {
By("allowing connections without a limit")

Eventually(func(g Gomega) {
response, err := client.CollectResponse(
Expand All @@ -105,31 +145,27 @@ spec:
g.Expect(response.Instance).To(Equal("kubernetes"))
}, "20s", "1s")

By("not allowing more than 1 connection")
By("allowing more than 1 connection without a limit")

// Open TCP connections to the gateway
go func() {
defer GinkgoRecover()

demoClientPod, err := PodNameOfApp(env.Cluster, "demo-client", waitingClientNamespace)
Expect(err).ToNot(HaveOccurred())

cmd := []string{"telnet", gatewayHost, "8080"}
// We pass in a stdin that blocks so that telnet will keep the
// connection open
_, _, _ = env.Cluster.ExecWithOptions(ExecOptions{
Command: cmd,
Namespace: waitingClientNamespace,
PodName: demoClientPod,
ContainerName: "demo-client",
Stdin: &BlockingReader{},
CaptureStdout: true,
CaptureStderr: true,
PreserveWhitespace: false,
Retries: DefaultRetries,
Timeout: DefaultTimeout,
})
}()
go keepConnectionOpen()

Consistently(func(g Gomega) {
response, err := client.CollectResponse(
env.Cluster, "demo-client", target,
client.FromKubernetesPod(curlingClientNamespace, "demo-client"),
)

g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("kubernetes"))
}, "40s", "1s").Should(Succeed())

By("not allowing more than 1 connection with a limit of 1")

Expect(env.Cluster.Install(YamlK8s(meshGatewayWithLimit))).To(Succeed())

Expect(env.Cluster.KillAppPod("demo-client", waitingClientNamespace)).To(Succeed())

go keepConnectionOpen()

Eventually(func(g Gomega) {
response, err := client.CollectFailure(
Expand Down
13 changes: 13 additions & 0 deletions test/framework/k8s_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,3 +1206,16 @@ func (c *K8sCluster) DeleteNodeViaApi(node string) error {
foreground := metav1.DeletePropagationForeground
return clientset.CoreV1().Nodes().Delete(context.Background(), node, metav1.DeleteOptions{PropagationPolicy: &foreground})
}

func (c *K8sCluster) KillAppPod(app, namespace string) error {
pod, err := PodNameOfApp(c, app, namespace)
if err != nil {
return err
}

if err := k8s.RunKubectlE(c.GetTesting(), c.GetKubectlOptions(namespace), "delete", "pod", pod); err != nil {
return err
}

return c.WaitApp(app, namespace, 1)
}

0 comments on commit 11389f9

Please sign in to comment.