From 0ed96b88527a291386217ed8af59f9118885aa01 Mon Sep 17 00:00:00 2001 From: Lukasz Dziedziak Date: Wed, 23 Oct 2024 11:43:30 +0200 Subject: [PATCH] test(e2e): use MeshService mode and generated hostname (#11832) I've noticed a flake of the test I switched to using MeshService mode instead of manually creating a MeshService. I'm not sure if MeshService might be removed since the Mesh has `meshServices.mode` disabled. Additionally, I changed the hostname to use generated one. Fix #XX --------- Signed-off-by: Lukasz Dziedziak --- .../universal/meshhealthcheck/policy.go | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/test/e2e_env/universal/meshhealthcheck/policy.go b/test/e2e_env/universal/meshhealthcheck/policy.go index 39524967b899..d3181e39f8cb 100644 --- a/test/e2e_env/universal/meshhealthcheck/policy.go +++ b/test/e2e_env/universal/meshhealthcheck/policy.go @@ -8,7 +8,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1" "github.com/kumahq/kuma/pkg/core/resources/apis/mesh" + "github.com/kumahq/kuma/pkg/test/resources/samples" . "github.com/kumahq/kuma/test/framework" "github.com/kumahq/kuma/test/framework/client" "github.com/kumahq/kuma/test/framework/envs/universal" @@ -55,6 +57,12 @@ spec: Expect(err).ToNot(HaveOccurred()) }) +<<<<<<< HEAD +======= + AfterEachFailure(func() { + DebugUniversal(universal.Cluster, meshName) + }) + E2EAfterAll(func() { Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed()) Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed()) @@ -92,6 +100,90 @@ spec: }) }, Ordered) + Describe("HTTP to real MeshService", func() { + meshName := "meshhealthcheck-http-ms" + healthCheck := func(mesh, method, status string) string { + return fmt.Sprintf(` +type: MeshHealthCheck +mesh: %s +name: everything-to-backend +spec: + to: + - targetRef: + kind: MeshService + name: test-server + default: + interval: 10s + timeout: 2s + unhealthyThreshold: 3 + healthyThreshold: 1 + failTrafficOnPanic: true + noTrafficInterval: 1s + healthyPanicThreshold: 0 + reuseConnection: true + http: + path: /%s + expectedStatuses: + - %s`, mesh, method, status) + } + + BeforeAll(func() { + err := NewClusterSetup(). + Install(Yaml(samples.MeshDefaultBuilder(). + WithName(meshName). + WithMeshServicesEnabled(mesh_proto.Mesh_MeshServices_Exclusive), + )). + Install(YamlUniversal(healthCheck(meshName, "health", "200"))). + Install(DemoClientUniversal("dp-demo-client", meshName, + WithTransparentProxy(true)), + ). + Install(TestServerUniversal("test-server", meshName, WithArgs([]string{"health-check", "http"}), WithProtocol(mesh.ProtocolHTTP))). + Setup(universal.Cluster) + Expect(err).ToNot(HaveOccurred()) + }) + + AfterEachFailure(func() { + DebugUniversal(universal.Cluster, meshName) + }) + +>>>>>>> 07ac2c772 (test(e2e): use MeshService mode and generated hostname (#11832)) + E2EAfterAll(func() { + Expect(universal.Cluster.DeleteMeshApps(meshName)).To(Succeed()) + Expect(universal.Cluster.DeleteMesh(meshName)).To(Succeed()) + }) + + It("should mark host as unhealthy if it doesn't reply on health checks", func() { + // check that test-server is healthy + Eventually(func(g Gomega) { + stdout, _, err := client.CollectResponse( + universal.Cluster, "dp-demo-client", "test-server.svc.mesh.local/content", + ) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(stdout).To(ContainSubstring("response")) + }).Should(Succeed()) + + // update HealthCheck policy to check for another status code + Expect(YamlUniversal(healthCheck(meshName, "are-you-healthy", "500"))(universal.Cluster)).To(Succeed()) + + // wait cluster 'test-server' to be marked as unhealthy + Eventually(func(g Gomega) { + cmd := []string{"/bin/bash", "-c", "\"curl localhost:9901/clusters | grep test-server\""} + stdout, _, err := universal.Cluster.Exec("", "", "dp-demo-client", cmd...) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(stdout).To(ContainSubstring("health_flags::/failed_active_hc")) + }, "30s", "500ms").Should(Succeed()) + + // check that test-server is unhealthy + Consistently(func(g Gomega) { + response, err := client.CollectFailure( + universal.Cluster, "dp-demo-client", "test-server.svc.mesh.local/content", + ) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(response.ResponseCode).To(Equal(503)) + }).Should(Succeed()) + }) + }, Ordered) + Describe("TCP", func() { healthCheck := func(mesh, serviceName, send, recv string) string { sendBase64 := base64.StdEncoding.EncodeToString([]byte(send))