Skip to content

Commit

Permalink
test: add service e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Feb 10, 2021
1 parent f9697ce commit df065f9
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: golangci-lint
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "github.com/alauda/kube-ovn/test/e2e/ip"
_ "github.com/alauda/kube-ovn/test/e2e/kubectl-ko"
_ "github.com/alauda/kube-ovn/test/e2e/node"
_ "github.com/alauda/kube-ovn/test/e2e/service"
_ "github.com/alauda/kube-ovn/test/e2e/subnet"
)

Expand Down
11 changes: 11 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,14 @@ func getPodInitStatus(pod corev1.Pod, reason string) (bool, string) {
}
return initializing, reason
}

func GetNodeInternalIP(node corev1.Node) string {
var nodeAddr string
for _, addr := range node.Status.Addresses {
if addr.Type == corev1.NodeInternalIP {
nodeAddr = addr.Address
break
}
}
return nodeAddr
}
143 changes: 143 additions & 0 deletions test/e2e/service/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package service

import (
"context"
"fmt"
"github.com/alauda/kube-ovn/test/e2e/framework"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"os/exec"
)

var _ = Describe("[Service]", func() {
f := framework.NewFramework("service", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME")))
hostPods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{LabelSelector: "app=ovs"})
Expect(err).NotTo(HaveOccurred())

containerPods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(context.Background(), metav1.ListOptions{LabelSelector: "app=kube-ovn-pinger"})
Expect(err).NotTo(HaveOccurred())

hostService, err := f.KubeClientSet.CoreV1().Services("kube-system").Get(context.Background(), "kube-ovn-cni", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
hostService.Spec.Type = corev1.ServiceTypeNodePort
hostService, err = f.KubeClientSet.CoreV1().Services("kube-system").Update(context.Background(), hostService, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred())

containerService, err := f.KubeClientSet.CoreV1().Services("kube-system").Get(context.Background(), "kube-ovn-pinger", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
containerService.Spec.Type = corev1.ServiceTypeNodePort
containerService, err = f.KubeClientSet.CoreV1().Services("kube-system").Update(context.Background(), containerService, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred())

It("host to host clusterIP", func() {
for _, pod := range hostPods.Items {
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", hostService.Spec.ClusterIP, hostService.Spec.Ports[0].Port), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
})

It("host to host NodePort", func() {
for _, pod := range hostPods.Items {
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
for _, node := range nodes.Items {
nodeIP := framework.GetNodeInternalIP(node)
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", nodeIP, hostService.Spec.Ports[0].NodePort), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
}
})

It("host to container clusterIP", func() {
for _, pod := range hostPods.Items {
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", containerService.Spec.ClusterIP, containerService.Spec.Ports[0].Port), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
})

It("host to container NodePort", func() {
for _, pod := range hostPods.Items {
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
for _, node := range nodes.Items {
nodeIP := framework.GetNodeInternalIP(node)
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", nodeIP, containerService.Spec.Ports[0].NodePort), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
}
})

It("container to container clusterIP", func() {
for _, pod := range containerPods.Items {
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", containerService.Spec.ClusterIP, containerService.Spec.Ports[0].Port), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
})

It("container to container NodePort", func() {
for _, pod := range containerPods.Items {
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
for _, node := range nodes.Items {
nodeIP := framework.GetNodeInternalIP(node)
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", nodeIP, containerService.Spec.Ports[0].NodePort), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
}
})

It("container to host clusterIP", func() {
for _, pod := range containerPods.Items {
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", hostService.Spec.ClusterIP, hostService.Spec.Ports[0].Port), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
})

It("container to host NodePort", func() {
for _, pod := range containerPods.Items {
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())
for _, node := range nodes.Items {
nodeIP := framework.GetNodeInternalIP(node)
output, err := exec.Command(
"kubectl", "exec", "-n", "kube-system", pod.Name, "--",
"curl", "-s", "-w", "%{http_code}", fmt.Sprintf("%s:%d/metrics", nodeIP, hostService.Spec.Ports[0].NodePort), "-o", "/dev/null",
).CombinedOutput()
Expect(err).NotTo(HaveOccurred(), string(output))
Expect(string(output)).To(Equal("200"))
}
}
})

})

0 comments on commit df065f9

Please sign in to comment.