-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from Roronoa-Z3r0/main
add macvlan overlay e2e
- Loading branch information
Showing
11 changed files
with
340 additions
and
19 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
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
121 changes: 119 additions & 2 deletions
121
test/e2e/macvlan-overlay-one/macvlan_overlay_one_suite_test.go
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 |
---|---|---|
@@ -1,13 +1,130 @@ | ||
package macvlan_overlay_one_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"context" | ||
"fmt" | ||
multus_v1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spidernet-io/cni-plugins/pkg/schema" | ||
"github.com/spidernet-io/cni-plugins/test/e2e/common" | ||
e2e "github.com/spidernet-io/e2eframework/framework" | ||
"github.com/spidernet-io/e2eframework/tools" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"net" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestMacvlanOverlayOne(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "MacvlanOverlayOne Suite") | ||
} | ||
|
||
var frame *e2e.Framework | ||
var name, namespace, multuNs string | ||
|
||
var podList *corev1.PodList | ||
var dp *appsv1.Deployment | ||
var labels, annotations = make(map[string]string), make(map[string]string) | ||
|
||
var port int32 = 80 | ||
var nodePorts []int32 | ||
var podIPs, clusterIPs, nodeIPs []string | ||
|
||
var retryTimes = 5 | ||
|
||
var _ = BeforeSuite(func() { | ||
defer GinkgoRecover() | ||
var e error | ||
frame, e = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{multus_v1.AddToScheme, schema.SpiderPoolAddToScheme}) | ||
Expect(e).NotTo(HaveOccurred()) | ||
|
||
// init namespace name and create | ||
name = "one-macvlan-overlay" | ||
namespace = "ns" + tools.RandomName() | ||
multuNs = "kube-system" | ||
labels["app"] = name | ||
|
||
err := frame.CreateNamespace(namespace) | ||
Expect(err).NotTo(HaveOccurred(), "failed to create namespace %v", namespace) | ||
GinkgoWriter.Printf("create namespace %v \n", namespace) | ||
|
||
// get macvlan-standalone multus crd instance by name | ||
multusInstance, err := frame.GetMultusInstance(common.MacvlanOverlayVlan100Name, multuNs) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(multusInstance).NotTo(BeNil()) | ||
annotations[common.MultusAddonAnnotation_Key] = fmt.Sprintf("%s/%s", multuNs, common.MacvlanOverlayVlan100Name) | ||
annotations[common.SpiderPoolIPPoolAnnotationKey] = `{"interface": "net1", "ipv4": ["vlan100-v4"], "ipv6": ["vlan100-v6"] }` | ||
|
||
GinkgoWriter.Printf("create deploy: %v/%v \n", namespace, name) | ||
dp = common.GenerateDeploymentYaml(name, namespace, labels, annotations) | ||
Expect(frame.CreateDeployment(dp)).NotTo(HaveOccurred()) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 2*common.CtxTimeout) | ||
defer cancel() | ||
|
||
err = frame.WaitPodListRunning(dp.Spec.Selector.MatchLabels, int(*dp.Spec.Replicas), ctx) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
podList, err = frame.GetDeploymentPodList(dp) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(podList).NotTo(BeNil()) | ||
|
||
// create nodePort service | ||
st := common.GenerateServiceYaml(name, namespace, port, dp.Spec.Selector.MatchLabels) | ||
err = frame.CreateService(st) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
GinkgoWriter.Printf("succeed to create nodePort service: %s/%s\n", namespace, name) | ||
|
||
// get clusterIPs & nodePorts | ||
service, err := frame.GetService(name, namespace) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(service).NotTo(BeNil(), "failed to get service: %s/%s", namespace, name) | ||
|
||
for _, ip := range service.Spec.ClusterIPs { | ||
if net.ParseIP(ip).To4() == nil && common.IPV6 { | ||
clusterIPs = append(clusterIPs, ip) | ||
} | ||
|
||
if net.ParseIP(ip).To4() != nil && common.IPV4 { | ||
clusterIPs = append(clusterIPs, ip) | ||
} | ||
} | ||
nodePorts = common.GetServiceNodePorts(service.Spec.Ports) | ||
GinkgoWriter.Printf("clusterIPs: %v\n", clusterIPs) | ||
|
||
// check service ready by get endpoint | ||
err = common.WaitEndpointReady(retryTimes, name, namespace, frame) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// get pod all ip | ||
podIPs, err = common.GetAllIPsFromPods(podList) | ||
Expect(err).NotTo(HaveOccurred(), err) | ||
Expect(podIPs).NotTo(BeNil()) | ||
GinkgoWriter.Printf("Get All PodIPs: %v\n", podIPs) | ||
|
||
nodeIPs, err = common.GetKindNodeIPs(context.TODO(), frame, frame.Info.KindNodeList) | ||
Expect(err).NotTo(HaveOccurred(), "failed to get all node ips: %v", err) | ||
Expect(nodeIPs).NotTo(BeNil()) | ||
GinkgoWriter.Printf("Get All Node ips: %v\n", nodeIPs) | ||
|
||
GinkgoWriter.Printf("Node list : %v \n", frame.Info.KindNodeList) | ||
time.Sleep(5 * time.Second) | ||
}) | ||
|
||
var _ = AfterSuite(func() { | ||
// delete deployment | ||
err := frame.DeleteDeployment(name, namespace) | ||
Expect(err).NotTo(HaveOccurred(), "failed to delete deployment %v/%v", namespace, name) | ||
|
||
// delete service | ||
err = frame.DeleteService(name, namespace) | ||
Expect(err).To(Succeed()) | ||
|
||
err = frame.DeleteNamespace(namespace) | ||
Expect(err).NotTo(HaveOccurred(), "failed to delete namespace %v", namespace) | ||
}) |
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 |
---|---|---|
@@ -1,9 +1,91 @@ | ||
package macvlan_overlay_one_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/spidernet-io/cni-plugins/test/e2e/common" | ||
"net" | ||
"os" | ||
) | ||
|
||
var _ = Describe("MacvlanOverlayOne", Label("overlay", "one-nic"), func() { | ||
It("Host can be communicate with pod, including pod in same and different node", Label("ping"), func() { | ||
for _, node := range frame.Info.KindNodeList { | ||
for _, podIP := range podIPs { | ||
command := common.GetPingCommandByIPFamily(podIP) | ||
_, err := frame.DockerExecCommand(context.TODO(), node, command) | ||
Expect(err).NotTo(HaveOccurred(), " host %s failed to ping %s: %v,", node, podIP, err) | ||
} | ||
} | ||
}) | ||
|
||
It("Pods in different node can be communicate with each other", Label("ping"), func() { | ||
for _, pod := range podList.Items { | ||
for _, podIP := range podIPs { | ||
command := common.GetPingCommandByIPFamily(podIP) | ||
_, err := frame.ExecCommandInPod(pod.Name, pod.Namespace, command, context.TODO()) | ||
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("pod %s/%s failed to %s", pod.Namespace, pod.Name, command)) | ||
} | ||
} | ||
}) | ||
|
||
// ping calico pod ? | ||
|
||
It("remote's client should be access to pod", Label("ping"), func() { | ||
// get remote's client container name | ||
vlanGatewayName := os.Getenv(common.ENV_VLAN_GATEWAY_CONTAINER) | ||
Expect(vlanGatewayName).NotTo(BeEmpty(), "failed to get env 'VLAN_GATEWAY_CONTAINER'") | ||
|
||
for _, podIP := range podIPs { | ||
command := common.GetPingCommandByIPFamily(podIP) | ||
_, err := frame.DockerExecCommand(context.TODO(), vlanGatewayName, command) | ||
Expect(err).To(Succeed()) | ||
} | ||
}) | ||
|
||
It("Pod should be access to clusterIP, including ipv4 and ipv6", Label("curl"), func() { | ||
for _, pod := range podList.Items { | ||
for _, clusterIP := range clusterIPs { | ||
// TODO https://github.com/projectcalico/calico/issues/6877 | ||
if net.ParseIP(clusterIP).To4() == nil { | ||
continue | ||
} | ||
command := common.GetCurlCommandByIPFamily(clusterIP, 80) | ||
output, err := frame.ExecCommandInPod(pod.Name, pod.Namespace, command, context.TODO()) | ||
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("pod %s/%s failed to %s: %s \n", pod.Namespace, pod.Name, command, output)) | ||
} | ||
} | ||
}) | ||
|
||
It("Host should be access to clusterIP, including ipv4 and ipv6", Label("curl"), func() { | ||
for _, node := range frame.Info.KindNodeList { | ||
for _, clusterIP := range clusterIPs { | ||
// TODO https://github.com/projectcalico/calico/issues/6877 | ||
if net.ParseIP(clusterIP).To4() == nil { | ||
continue | ||
} | ||
command := common.GetCurlCommandByIPFamily(clusterIP, 80) | ||
GinkgoWriter.Printf("docker exec -it %s %s \n", node, command) | ||
output, err := frame.DockerExecCommand(context.TODO(), node, command) | ||
Expect(err).NotTo(HaveOccurred(), " host %s failed to access to cluster service %s: %s,", node, clusterIP, output) | ||
} | ||
} | ||
|
||
}) | ||
It("Host should be access to nodePort address, including ipv4 and ipv6", Label("curl"), func() { | ||
for _, node := range frame.Info.KindNodeList { | ||
for _, nodeIP := range nodeIPs { | ||
// TODO https://github.com/projectcalico/calico/issues/6877 | ||
if net.ParseIP(nodeIP).To4() == nil { | ||
continue | ||
} | ||
command := common.GetCurlCommandByIPFamily(nodeIP, nodePorts[0]) | ||
GinkgoWriter.Printf("docker exec -it %s %s \n", node, command) | ||
output, err := frame.DockerExecCommand(context.TODO(), node, command) | ||
Expect(err).NotTo(HaveOccurred(), " host %s failed to access to nodePort service %s/%d: %s \n", node, nodeIP, nodePorts[0], output) | ||
} | ||
} | ||
}) | ||
}) |
Oops, something went wrong.