Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gateway): skip ExternalService if none match #5207

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/plugins/runtime/gateway/cluster_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ func (c *ClusterGenerator) GenerateClusters(ctx context.Context, xdsCtx xds_cont
// an external service. Because the dataplane endpoints happen to be
// generated first, the mesh service will have priority.
for _, dest := range routeDestinationsMutable(hostInfo.Entries) {
matched := match.ExternalService(info.ExternalServices.Items, mesh_proto.TagSelector(dest.Destination))
service := dest.Destination[mesh_proto.ServiceTag]

firstEndpointExternalService := route.HasExternalServiceEndpoint(xdsCtx.Mesh.Resource, info.OutboundEndpoints, *dest)

matched := match.ExternalService(info.ExternalServices.Items, mesh_proto.TagSelector(dest.Destination))

// If there is Mesh property ZoneEgress enabled we want always to
// direct the traffic through them. The condition is, the mesh must
// have mTLS enabled and traffic through zoneEgress is enabled.
isDirectExternalService := firstEndpointExternalService && !xdsCtx.Mesh.Resource.ZoneEgressEnabled()
isExternalServiceThroughZoneEgress := firstEndpointExternalService && !isDirectExternalService
isExternalCluster := isDirectExternalService && len(matched) > 0

isExternalServiceThroughZoneEgress := firstEndpointExternalService && xdsCtx.Mesh.Resource.ZoneEgressEnabled()

var r *core_xds.Resource
var err error

if isDirectExternalService {
if isExternalCluster {
log.V(1).Info("generating external service cluster",
"service", service,
)
Expand Down Expand Up @@ -80,7 +83,7 @@ func (c *ClusterGenerator) GenerateClusters(ctx context.Context, xdsCtx xds_cont
// reference it.
dest.Name = r.Name

if isDirectExternalService {
if isExternalCluster {
// External clusters don't get a load assignment.
continue
}
Expand Down
49 changes: 48 additions & 1 deletion test/e2e_env/kubernetes/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,15 @@ spec:
testserver.WithEchoArgs("echo", "--instance", "es-echo-server"),
)).
Install(YamlK8s(externalService)).
Install(YamlK8s(route("es-echo-server", "/external-service", "external-service"))).
Setup(env.Cluster)
Expect(err).ToNot(HaveOccurred())
})

It("should proxy to service via HTTP", func() {
route := route("es-echo-server", "/external-service", "external-service")
setup := NewClusterSetup().Install(YamlK8s(route))
Expect(setup.Setup(env.Cluster)).To(Succeed())

Eventually(func(g Gomega) {
response, err := client.CollectResponse(
env.Cluster, "demo-client",
Expand All @@ -239,6 +242,50 @@ spec:
g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.Instance).To(Equal("es-echo-server"))
}, "30s", "1s").Should(Succeed())

Expect(NewClusterSetup().Install(DeleteYamlK8s(route)).Setup(env.Cluster)).To(Succeed())
})

It("should handle external-service excluded by tags", func() {
route := fmt.Sprintf(`
apiVersion: kuma.io/v1alpha1
kind: MeshGatewayRoute
metadata:
name: %s
mesh: simple-gateway
spec:
selectors:
- match:
kuma.io/service: simple-gateway
conf:
http:
rules:
- matches:
- path:
match: PREFIX
value: %s
backends:
- destination:
kuma.io/service: %s
nonexistent: tag
`, "es-echo-server-broken", "/external-service", "external-service")

setup := NewClusterSetup().Install(YamlK8s(route))
Expect(setup.Setup(env.Cluster)).To(Succeed())

Eventually(func(g Gomega) {
response, err := client.CollectFailure(
env.Cluster, "demo-client",
"http://simple-gateway.simple-gateway:8080/external-service",
client.WithHeader("host", "example.kuma.io"),
client.FromKubernetesPod(clientNamespace, "demo-client"),
)

g.Expect(err).ToNot(HaveOccurred())
g.Expect(response.ResponseCode).To(Equal(503))
}, "30s", "1s").Should(Succeed())

Expect(NewClusterSetup().Install(DeleteYamlK8s(route)).Setup(env.Cluster)).To(Succeed())
})
})
}