-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package e2e_ebpf | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
kubeovn "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1" | ||
"github.com/kubeovn/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" | ||
"testing" | ||
|
||
_ "github.com/kubeovn/kube-ovn/test/e2e-ebpf/service" | ||
_ "github.com/kubeovn/kube-ovn/test/e2e/ip" | ||
_ "github.com/kubeovn/kube-ovn/test/e2e/subnet" | ||
) | ||
|
||
func TestE2eEbpf(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Kube-OVN E2E ebpf Suite") | ||
} | ||
|
||
var _ = SynchronizedAfterSuite(func() {}, func() { | ||
f := framework.NewFramework("init", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME"))) | ||
nss, err := f.KubeClientSet.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{LabelSelector: "e2e=true"}) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
if nss != nil { | ||
for _, ns := range nss.Items { | ||
err := f.KubeClientSet.CoreV1().Namespaces().Delete(context.Background(), ns.Name, metav1.DeleteOptions{}) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
} | ||
} | ||
|
||
err = f.OvnClientSet.KubeovnV1().Subnets().DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "e2e=true"}) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
}) | ||
|
||
var _ = SynchronizedBeforeSuite(func() []byte { | ||
subnetName := "static-ip" | ||
namespace := "static-ip" | ||
f := framework.NewFramework("init", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME"))) | ||
|
||
_, err := f.KubeClientSet.CoreV1().Namespaces().Create(context.Background(), &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: namespace, | ||
Labels: map[string]string{"e2e": "true"}}}, metav1.CreateOptions{}) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
|
||
s := kubeovn.Subnet{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: subnetName, | ||
Labels: map[string]string{"e2e": "true"}, | ||
}, | ||
Spec: kubeovn.SubnetSpec{ | ||
CIDRBlock: "12.10.0.0/16", | ||
Namespaces: []string{namespace}, | ||
}, | ||
} | ||
_, err = f.OvnClientSet.KubeovnV1().Subnets().Create(context.Background(), &s, metav1.CreateOptions{}) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
err = f.WaitSubnetReady(subnetName) | ||
if err != nil { | ||
Fail(err.Error()) | ||
} | ||
|
||
return nil | ||
}, func(data []byte) {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package service | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/kubeovn/kube-ovn/pkg/util" | ||
"github.com/kubeovn/kube-ovn/test/e2e/framework" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func nodeIPs(node corev1.Node) []string { | ||
nodeIPv4, nodeIPv6 := util.GetNodeInternalIP(node) | ||
var nodeIPs []string | ||
if nodeIPv4 != "" { | ||
nodeIPs = append(nodeIPs, nodeIPv4) | ||
} | ||
if nodeIPv6 != "" { | ||
nodeIPs = append(nodeIPs, nodeIPv6) | ||
} | ||
return nodeIPs | ||
} | ||
|
||
func kubectlArgs(pod, ip string, port int32) string { | ||
return fmt.Sprintf("-n kube-system exec %s -- curl %s", pod, curlArgs(ip, port)) | ||
} | ||
|
||
func curlArgs(ip string, port int32) string { | ||
return fmt.Sprintf("-s -m 3 -o /dev/null -w %%{http_code} %s/metrics", util.JoinHostPort(ip, port)) | ||
} | ||
|
||
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()) | ||
|
||
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()) | ||
|
||
Context("service with container network endpoints", func() { | ||
It("container to ClusterIP", func() { | ||
port := containerService.Spec.Ports[0].Port | ||
for _, ip := range containerService.Spec.ClusterIPs { | ||
for _, pod := range containerPods.Items { | ||
output, err := exec.Command("kubectl", strings.Fields(kubectlArgs(pod.Name, ip, port))...).CombinedOutput() | ||
outputStr := string(bytes.TrimSpace(output)) | ||
Expect(err).NotTo(HaveOccurred(), outputStr) | ||
Expect(outputStr).To(Equal("200")) | ||
} | ||
} | ||
}) | ||
|
||
It("host to ClusterIP", func() { | ||
port := containerService.Spec.Ports[0].Port | ||
for _, ip := range containerService.Spec.ClusterIPs { | ||
for _, pod := range hostPods.Items { | ||
output, err := exec.Command("kubectl", strings.Fields(kubectlArgs(pod.Name, ip, port))...).CombinedOutput() | ||
outputStr := string(bytes.TrimSpace(output)) | ||
Expect(err).NotTo(HaveOccurred(), outputStr) | ||
Expect(outputStr).To(Equal("200")) | ||
} | ||
} | ||
}) | ||
|
||
It("container to NodePort", func() { | ||
port := containerService.Spec.Ports[0].NodePort | ||
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 { | ||
for _, nodeIP := range nodeIPs(node) { | ||
output, err := exec.Command("kubectl", strings.Fields(kubectlArgs(pod.Name, nodeIP, port))...).CombinedOutput() | ||
outputStr := string(bytes.TrimSpace(output)) | ||
Expect(err).NotTo(HaveOccurred(), outputStr) | ||
Expect(outputStr).To(Equal("200")) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
It("host to NodePort", func() { | ||
port := containerService.Spec.Ports[0].NodePort | ||
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 { | ||
for _, nodeIP := range nodeIPs(node) { | ||
output, err := exec.Command("kubectl", strings.Fields(kubectlArgs(pod.Name, nodeIP, port))...).CombinedOutput() | ||
outputStr := string(bytes.TrimSpace(output)) | ||
Expect(err).NotTo(HaveOccurred(), outputStr) | ||
Expect(outputStr).To(Equal("200")) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
It("external to NodePort", func() { | ||
if runtime.GOOS != "linux" { | ||
return | ||
} | ||
|
||
port := containerService.Spec.Ports[0].NodePort | ||
nodes, err := f.KubeClientSet.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
for _, node := range nodes.Items { | ||
for _, nodeIP := range nodeIPs(node) { | ||
output, err := exec.Command("curl", strings.Fields(curlArgs(nodeIP, port))...).CombinedOutput() | ||
outputStr := string(bytes.TrimSpace(output)) | ||
Expect(err).To(HaveOccurred(), outputStr) | ||
} | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: cni-configuration | ||
namespace: kube-system | ||
data: | ||
cni-config: |- | ||
{ | ||
"name": "generic-veth", | ||
"cniVersion": "0.3.1", | ||
"plugins": [ | ||
{ | ||
"type": "kube-ovn", | ||
"log_level": "info", | ||
"datastore_type": "kubernetes", | ||
"mtu": 1400, | ||
"server_socket": "/run/openvswitch/kube-ovn-daemon.sock", | ||
"ipam": { | ||
"type": "kube-ovn", | ||
"server_socket": "/run/openvswitch/kube-ovn-daemon.sock" | ||
} | ||
}, | ||
{ | ||
"type": "portmap", | ||
"snat": true, | ||
"capabilities": {"portMappings": true} | ||
}, | ||
{ | ||
"type": "cilium-cni" | ||
} | ||
] | ||
} |