Backport of [NET-5810] CE changes for multiple virtual hosts into release/1.17.x (#19247)

backport of commit c5018c1da7

Co-authored-by: jm96441n <john.maguire@hashicorp.com>
pull/19251/head
hc-github-team-consul-core 2023-10-17 11:33:12 -04:00 committed by GitHub
parent bf42dd6c4c
commit 1c91abd23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 37 deletions

View File

@ -152,7 +152,11 @@ func (s *ResourceGenerator) makeAPIGatewayListeners(address string, cfgSnap *pro
routes := make([]*structs.HTTPRouteConfigEntry, 0, len(readyListener.routeReferences)) routes := make([]*structs.HTTPRouteConfigEntry, 0, len(readyListener.routeReferences))
for _, routeRef := range maps.Keys(readyListener.routeReferences) { for _, routeRef := range maps.Keys(readyListener.routeReferences) {
route, _ := cfgSnap.APIGateway.HTTPRoutes.Get(routeRef) route, ok := cfgSnap.APIGateway.HTTPRoutes.Get(routeRef)
if !ok {
return nil, fmt.Errorf("missing route for routeRef %s:%s", routeRef.Kind, routeRef.Name)
}
routes = append(routes, route) routes = append(routes, route)
} }
consolidatedRoutes := discoverychain.ConsolidateHTTPRoutes(cfgSnap.APIGateway.GatewayConfig, &readyListener.listenerCfg, routes...) consolidatedRoutes := discoverychain.ConsolidateHTTPRoutes(cfgSnap.APIGateway.GatewayConfig, &readyListener.listenerCfg, routes...)
@ -297,11 +301,9 @@ func getReadyListeners(cfgSnap *proxycfg.ConfigSnapshot) map[string]readyListene
continue continue
} }
routeKey := l.Name + routeRef.String()
for _, upstream := range routeUpstreamsForListener { for _, upstream := range routeUpstreamsForListener {
// Insert or update readyListener for the listener to include this upstream // Insert or update readyListener for the listener to include this upstream
r, ok := ready[routeKey] r, ok := ready[l.Name]
if !ok { if !ok {
r = readyListener{ r = readyListener{
listenerKey: listenerKey, listenerKey: listenerKey,
@ -312,7 +314,7 @@ func getReadyListeners(cfgSnap *proxycfg.ConfigSnapshot) map[string]readyListene
} }
r.routeReferences[routeRef] = struct{}{} r.routeReferences[routeRef] = struct{}{}
r.upstreams = append(r.upstreams, upstream) r.upstreams = append(r.upstreams, upstream)
ready[routeKey] = r ready[l.Name] = r
} }
} }
} }

View File

@ -1,30 +1,6 @@
{ {
"nonce": "00000001", "nonce": "00000001",
"resources": [ "resources": [
{
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"name": "8080",
"validateClusters": true,
"virtualHosts": [
{
"domains": [
"backend.example.com",
"backend.example.com:8080"
],
"name": "api-gateway-http-5a84e719",
"routes": [
{
"match": {
"prefix": "/"
},
"route": {
"cluster": "backend.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
}
}
]
}
]
},
{ {
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration",
"name": "8080", "name": "8080",
@ -46,14 +22,24 @@
} }
} }
] ]
} },
] {
}, "domains": [
{ "backend.example.com",
"@type": "type.googleapis.com/envoy.config.route.v3.RouteConfiguration", "backend.example.com:8080"
"name": "8080", ],
"validateClusters": true, "name": "api-gateway-http-5a84e719",
"virtualHosts": [ "routes": [
{
"match": {
"prefix": "/"
},
"route": {
"cluster": "backend.default.dc1.internal.11111111-2222-3333-4444-555555555555.consul"
}
}
]
},
{ {
"domains": [ "domains": [
"*.example.com", "*.example.com",