Skip to content

Commit

Permalink
feat(meshexternalservice): try adding test
Browse files Browse the repository at this point in the history
Signed-off-by: slonka <[email protected]>
  • Loading branch information
slonka committed Sep 12, 2024
1 parent 052bb5c commit a20af1b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
81 changes: 72 additions & 9 deletions test/e2e_env/kubernetes/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type: system.kuma.io/secret

BeforeAll(func() {
err := NewClusterSetup().
Install(MTLSMeshKubernetes(meshName)).
Install(MTLSMeshKubernetesWithEgressRouting(meshName)).
Install(Namespace(clientNamespace)).
Install(NamespaceWithSidecarInjection(namespace)).
Install(testserver.Install(
Expand Down Expand Up @@ -236,7 +236,11 @@ spec:
}
}

httpRoute := func(name, path, destination string) []string {
httpRoute := func(name, path, destination, destinationKind, port string) []string {
portValue := ""
if port != "" {
portValue = "port: " + port
}
return []string{
fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
Expand All @@ -260,8 +264,9 @@ spec:
value: "%s"
default:
backendRefs:
- kind: MeshService
- kind: %s
name: "%s"
%s
- targetRef:
kind: Mesh
hostnames:
Expand All @@ -279,9 +284,10 @@ spec:
- name: x-specific-hostname-header
value: "true"
backendRefs:
- kind: MeshService
- kind: %s
name: "%s"
`, name, Config.KumaNamespace, path, destination, path, destination),
%s
`, name, Config.KumaNamespace, path, destinationKind, destination, portValue, path, destinationKind, destination, portValue),
fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: MeshHTTPRoute
Expand Down Expand Up @@ -312,9 +318,10 @@ spec:
- name: x-listener-by-hostname-header
value: "true"
backendRefs:
- kind: MeshService
- kind: %s
name: "%s"
`, name+"-hostname-specific", Config.KumaNamespace, path, destination),
%s
`, name+"-hostname-specific", Config.KumaNamespace, path, destinationKind, destination, portValue),
}
}

Expand Down Expand Up @@ -465,7 +472,7 @@ spec:
}

basicRouting("MeshGatewayRoute", meshGatewayRoutes("internal-service", "/", "echo-server_simple-gateway_svc_80"))
basicRouting("MeshHTTPRoute", httpRoute("internal-service", "/", "echo-server_simple-gateway_svc_80"))
basicRouting("MeshHTTPRoute", httpRoute("internal-service", "/", "echo-server_simple-gateway_svc_80", "MeshService", ""))

Context("Rate Limit", func() {
rt := `apiVersion: kuma.io/v1alpha1
Expand Down Expand Up @@ -550,7 +557,7 @@ spec:
header:
name: x-header
`, Config.KumaNamespace, meshName)
routes := httpRoute("test-server-mlbs", "/mlbs", "test-server-mlbs_simple-gateway_svc_80")
routes := httpRoute("test-server-mlbs", "/mlbs", "test-server-mlbs_simple-gateway_svc_80", "MeshService", "")

BeforeAll(func() {
err := NewClusterSetup().
Expand Down Expand Up @@ -1156,4 +1163,60 @@ spec:
Expect(NewClusterSetup().Install(DeleteYamlK8s(route)).Setup(kubernetes.Cluster)).To(Succeed())
})
})

FContext("MeshExternalService", func() {
meshExternalService := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: MeshExternalService
metadata:
name: simple-gateway-mesh-external-service
namespace: %s
labels:
kuma.io/mesh: %s
spec:
match:
type: HostnameGenerator
port: 80
protocol: http
endpoints:
- address: mes-echo-server.client-simple-gateway.svc.cluster.local
port: 80`, Config.KumaNamespace, meshName)

routes := httpRoute("test-server-mes", "/mes", "simple-gateway-mesh-external-service", "MeshExternalService", "80")

BeforeAll(func() {
err := NewClusterSetup().
Install(testserver.Install(
testserver.WithNamespace(clientNamespace),
testserver.WithName("mes-echo-server"),
)).
Install(YamlK8s(meshExternalService)).
Install(YamlK8s(routes...)).
Setup(kubernetes.Cluster)
Expect(err).ToNot(HaveOccurred())
})

E2EAfterAll(func() {
err := NewClusterSetup().
Install(DeleteYamlK8s(routes...)).
Install(DeleteYamlK8s(meshExternalService)).
Setup(kubernetes.Cluster)
Expect(err).ToNot(HaveOccurred())
})

FIt("should route to MeshExternalService", func() {
Eventually(func(g Gomega) {
responses, err := client.CollectResponsesByInstance(
kubernetes.Cluster, "demo-client",
"http://simple-gateway.simple-gateway:8080/mes",
client.WithHeader("host", "example.kuma.io"),
client.FromKubernetesPod(clientNamespace, "demo-client"),
client.WithHeader("x-header", "value"),
)

g.Expect(err).ToNot(HaveOccurred())
g.Expect(responses).To(HaveLen(1))
}, "30s", "1s").MustPassRepeatedly(5).Should(Succeed())
})
})
}
2 changes: 1 addition & 1 deletion test/e2e_env/kubernetes/kubernetes_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (

var (
_ = Describe("Virtual Probes", healthcheck.VirtualProbes, Ordered)
_ = Describe("Gateway", gateway.Gateway, Ordered)
_ = FDescribe("Gateway", gateway.Gateway, Ordered)
_ = Describe("Gateway - Cross-mesh", gateway.CrossMeshGatewayOnKubernetes, Ordered)
_ = Describe("Gateway - Gateway API", gateway.GatewayAPI, Ordered)
_ = Describe("Gateway - mTLS", gateway.Mtls, Ordered)
Expand Down
18 changes: 18 additions & 0 deletions test/framework/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ spec:
return YamlK8s(mesh)
}

func MTLSMeshKubernetesWithEgressRouting(name string) InstallFunc {
mesh := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: Mesh
metadata:
name: %s
spec:
routing:
zoneEgress: true
mtls:
enabledBackend: ca-1
backends:
- name: ca-1
type: builtin
`, name)
return YamlK8s(mesh)
}

func MTLSMeshWithMeshServicesKubernetes(name string, meshServicesEnabled string) InstallFunc {
mesh := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
Expand Down

0 comments on commit a20af1b

Please sign in to comment.