From bb6b9b7e8385262f0469d9cbc8ad114fc451c1b6 Mon Sep 17 00:00:00 2001 From: Harish Dendukuri <98586849+harish2773@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:31:28 +0530 Subject: [PATCH 1/2] added e2e test for locality aware load balancing --- test/e2e/locality_aware_lb_test.go | 228 +++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 test/e2e/locality_aware_lb_test.go diff --git a/test/e2e/locality_aware_lb_test.go b/test/e2e/locality_aware_lb_test.go new file mode 100644 index 000000000..25e51b909 --- /dev/null +++ b/test/e2e/locality_aware_lb_test.go @@ -0,0 +1,228 @@ +package e2e + +import ( + "os/exec" + "strings" + "testing" + "time" +) + +func runCommand(command string) (string, error) { + cmd := exec.Command("bash", "-c", command) + out, err := cmd.CombinedOutput() + return string(out), err +} + +func TestLocalityAwareLoadBalancing(t *testing.T) { + t.Run("Setup Kind Cluster", func(t *testing.T) { + t.Log("Setting up Kind cluster...") + out, err := runCommand(`kind delete clusters --all || true && +kind create cluster --image=kindest/node:v1.31.0 --config=- < sleep.yaml && kubectl apply -f sleep.yaml") + if err != nil { + t.Fatalf("Failed to apply sleep client: %v\n%s", err, out) + } + + + time.Sleep(10 * time.Second) + + + out, err = runCommand("kubectl get deployment sleep -n sample") + if err != nil { + debugOut, _ := runCommand("kubectl get all -n sample") + t.Fatalf("Sleep deployment not found: %v\n%s\nResources in namespace:\n%s", err, out, debugOut) + } + + + t.Logf("Sleep deployment status: %s", out) + + podOut, _ := runCommand("kubectl get pods -n sample -l app=sleep -o wide") + t.Logf("Sleep pod status: %s", podOut) + + + out, err = runCommand("kubectl wait --for=condition=ready pod -n sample -l app=sleep --timeout=120s") + if err != nil { + + podDetails, _ := runCommand("kubectl describe pods -n sample -l app=sleep") + t.Fatalf("Failed to wait for sleep pod readiness: %v\n%s\nPod details:\n%s", err, out, podDetails) + } + + + out, err = runCommand(`kubectl exec -n sample "$(kubectl get pod -n sample -l app=sleep -o jsonpath='{.items[0].metadata.name}')" -- curl -sSL "http://helloworld:5000/hello"`) + if err != nil { + t.Fatalf("Failed to test service: %v\n%s", err, out) + } + + t.Logf("Output: %s", out) + }) + + t.Run("Cleanup", func(t *testing.T) { + t.Log("Cleaning up...") + + + _, err := runCommand("kubectl delete namespace sample || true") + if err != nil { + t.Logf("Failed to delete namespace: %v", err) + } + + + out, err := runCommand("kind delete clusters --all") + if err != nil { + t.Logf("Failed to delete cluster: %v\n%s", err, out) + } + }) +} \ No newline at end of file From 714dad2bb9f1e551b12d1014fcc70823cf516cc4 Mon Sep 17 00:00:00 2001 From: Harish Dendukuri <98586849+harish2773@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:40:57 +0530 Subject: [PATCH 2/2] added test header and description --- test/e2e/locality_aware_lb_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/e2e/locality_aware_lb_test.go b/test/e2e/locality_aware_lb_test.go index 25e51b909..862f180a9 100644 --- a/test/e2e/locality_aware_lb_test.go +++ b/test/e2e/locality_aware_lb_test.go @@ -1,3 +1,24 @@ +//go:build integ +// +build integ + +/* +End-to-End Test for Kmesh Locality-Aware Load Balancing. + +This test verifies that Kmesh correctly routes traffic to the nearest available instance +based on locality (region, zone, and subzone). The test performs the following steps: +1. Create a Kind cluster with three worker nodes. +2. Label the nodes with region, zone, and subzone information. +3. Deploy a helloworld service. +4. Deploy three instances of the helloworld service on different nodes: + - A local instance on "ambient-worker" with version "region.zone1.subzone1". + - A remote instance on "ambient-worker2" with version "region.zone1.subzone2". + - A remote instance on "ambient-worker3" with version "region.zone2.subzone3". +5. Deploy a sleep client on "ambient-worker" and validate: + - Traffic initially routes to the local instance. + - After deleting the local instance, traffic should fail over to the nearest available remote instance. +6. Clean up all resources after the test. +*/ + package e2e import ( @@ -225,4 +246,4 @@ spec: t.Logf("Failed to delete cluster: %v\n%s", err, out) } }) -} \ No newline at end of file +}