mirror of https://github.com/hashicorp/consul
xds: allow http match criteria to be applied to routes on services using grpc protocols (#6149)
parent
f946545b28
commit
d7a5158805
|
@ -186,13 +186,6 @@ func makeUpstreamRouteForDiscoveryChain(
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeRouteMatchForDiscoveryRoute(discoveryRoute *structs.DiscoveryRoute, protocol string) envoyroute.RouteMatch {
|
func makeRouteMatchForDiscoveryRoute(discoveryRoute *structs.DiscoveryRoute, protocol string) envoyroute.RouteMatch {
|
||||||
switch protocol {
|
|
||||||
case "http", "http2":
|
|
||||||
// The only match stanza is HTTP.
|
|
||||||
default:
|
|
||||||
return makeDefaultRouteMatch()
|
|
||||||
}
|
|
||||||
|
|
||||||
match := discoveryRoute.Definition.Match
|
match := discoveryRoute.Definition.Match
|
||||||
if match == nil || match.IsEmpty() {
|
if match == nil || match.IsEmpty() {
|
||||||
return makeDefaultRouteMatch()
|
return makeDefaultRouteMatch()
|
||||||
|
|
|
@ -79,6 +79,32 @@ func TestRoutesFromSnapshot(t *testing.T) {
|
||||||
},
|
},
|
||||||
setup: nil,
|
setup: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "connect-proxy-with-grpc-router",
|
||||||
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
||||||
|
return proxycfg.TestConfigSnapshotDiscoveryChainWithEntries(t,
|
||||||
|
&structs.ProxyConfigEntry{
|
||||||
|
Kind: structs.ProxyDefaults,
|
||||||
|
Name: structs.ProxyConfigGlobal,
|
||||||
|
Config: map[string]interface{}{
|
||||||
|
"protocol": "grpc",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&structs.ServiceRouterConfigEntry{
|
||||||
|
Kind: structs.ServiceRouter,
|
||||||
|
Name: "db",
|
||||||
|
Routes: []structs.ServiceRoute{
|
||||||
|
{
|
||||||
|
Match: httpMatch(&structs.ServiceRouteHTTPMatch{
|
||||||
|
PathExact: "/fgrpc.PingServer/Ping",
|
||||||
|
}),
|
||||||
|
Destination: toService("prefix"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "connect-proxy-with-chain-and-router",
|
name: "connect-proxy-with-chain-and-router",
|
||||||
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
create: func(t testinf.T) *proxycfg.ConfigSnapshot {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"versionInfo": "00000001",
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"@type": "type.googleapis.com/envoy.api.v2.RouteConfiguration",
|
||||||
|
"name": "db",
|
||||||
|
"virtualHosts": [
|
||||||
|
{
|
||||||
|
"name": "db",
|
||||||
|
"domains": [
|
||||||
|
"*"
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"match": {
|
||||||
|
"path": "/fgrpc.PingServer/Ping"
|
||||||
|
},
|
||||||
|
"route": {
|
||||||
|
"cluster": "prefix.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"match": {
|
||||||
|
"prefix": "/"
|
||||||
|
},
|
||||||
|
"route": {
|
||||||
|
"cluster": "db.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"validateClusters": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeUrl": "type.googleapis.com/envoy.api.v2.RouteConfiguration",
|
||||||
|
"nonce": "00000001"
|
||||||
|
}
|
Loading…
Reference in New Issue