Skip to content

Commit

Permalink
Add e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Yusuke Suzuki <[email protected]>
  • Loading branch information
ysksuzuki committed Sep 23, 2023
1 parent a71623c commit ff99d4b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
45 changes: 45 additions & 0 deletions v2/e2e/coil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ var _ = Describe("Coil", func() {
}
return int(depl.Status.ReadyReplicas)
}).Should(Equal(2))

By("defining Egress with fouSourcePortAuto in the internet namespace")
kubectlSafe(nil, "apply", "-f", "manifests/egress-sport-auto.yaml")

By("checking pod deployments for fouSourcePortAuto")
Eventually(func() int {
depl := &appsv1.Deployment{}
err := getResource("internet", "deployments", "egress-sport-auto", "", depl)
if err != nil {
return 0
}
return int(depl.Status.ReadyReplicas)
}).Should(Equal(2))
})

It("should be able to run NAT client pods", func() {
Expand All @@ -280,6 +293,26 @@ var _ = Describe("Coil", func() {
}
return nil
}).Should(Succeed())

By("creating a NAT client pod for fouSourcePortAuto")
kubectlSafe(nil, "apply", "-f", "manifests/nat-client-sport-auto.yaml")

By("checking the pod status for fouSourcePortAuto")
Eventually(func() error {
pod := &corev1.Pod{}
err := getResource("default", "pods", "nat-client-sport-auto", "", pod)
if err != nil {
return err
}
if len(pod.Status.ContainerStatuses) == 0 {
return errors.New("no container status")
}
cst := pod.Status.ContainerStatuses[0]
if !cst.Ready {
return errors.New("container is not ready")
}
return nil
}).Should(Succeed())
})

It("should allow NAT traffic over foo-over-udp tunnel", func() {
Expand Down Expand Up @@ -319,5 +352,17 @@ var _ = Describe("Coil", func() {
resp := kubectlSafe(data, "exec", "-i", "nat-client", "--", "curl", "-sf", "-T", "-", fakeURL)
Expect(resp).To(HaveLen(1 << 20))
}

By("sending and receiving HTTP request from nat-client-sport-auto")
data = make([]byte, 1<<20) // 1 MiB
resp = kubectlSafe(data, "exec", "-i", "nat-client-sport-auto", "--", "curl", "-sf", "-T", "-", fakeURL)
Expect(resp).To(HaveLen(1 << 20))

By("running the same test 100 times with nat-client-sport-auto")
for i := 0; i < 100; i++ {
time.Sleep(1 * time.Millisecond)
resp := kubectlSafe(data, "exec", "-i", "nat-client-sport-auto", "--", "curl", "-sf", "-T", "-", fakeURL)
Expect(resp).To(HaveLen(1 << 20))
}
})
})
20 changes: 20 additions & 0 deletions v2/e2e/manifests/egress-sport-auto.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: coil.cybozu.com/v2
kind: Egress
metadata:
name: egress-sport-auto
namespace: internet
spec:
replicas: 2
destinations:
- 0.0.0.0/0
- ::/0
fouSourcePortAuto: true
template:
spec:
nodeSelector:
kubernetes.io/hostname: coil-control-plane
tolerations:
- effect: NoSchedule
operator: Exists
containers:
- name: egress
17 changes: 17 additions & 0 deletions v2/e2e/manifests/nat-client-sport-auto.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
name: nat-client-sport-auto
namespace: default
annotations:
egress.coil.cybozu.com/internet: egress-sport-auto
spec:
tolerations:
- key: test
operator: Exists
nodeSelector:
test: coil
containers:
- name: ubuntu
image: quay.io/cybozu/ubuntu:22.04
command: ["pause"]

0 comments on commit ff99d4b

Please sign in to comment.