@ -58,7 +58,7 @@ func (s *ResourceGenerator) routesForConnectProxy(cfgSnap *proxycfg.ConfigSnapsh
continue
continue
}
}
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , [ ] string { "*" } , false )
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , [ ] string { "*" } , false , perRouteFilterBuilder { } )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -94,12 +94,12 @@ func (s *ResourceGenerator) routesForConnectProxy(cfgSnap *proxycfg.ConfigSnapsh
addressesMap [ routeName ] = make ( map [ string ] string )
addressesMap [ routeName ] = make ( map [ string ] string )
}
}
// cluster name is unique per address/port so we should not be doing any override here
// cluster name is unique per address/port so we should not be doing any override here
clusterName := clusterNameForDestination ( cfgSnap , svcConfig . Name , address , svcConfig . NamespaceOrDefault ( ) , svcConfig . PartitionOrDefault ( ) )
clusterName := clusterNameForDestination ( cfgSnap , svcConfig . Name , address , svcConfig . NamespaceOrDefault ( ) , svcConfig . PartitionOrDefault ( ) )
addressesMap [ routeName ] [ clusterName ] = address
addressesMap [ routeName ] [ clusterName ] = address
}
}
return nil
return nil
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -119,7 +119,6 @@ func (s *ResourceGenerator) routesForConnectProxy(cfgSnap *proxycfg.ConfigSnapsh
}
}
func ( s * ResourceGenerator ) makeRoutesForAddresses ( routeName string , addresses map [ string ] string ) ( [ ] proto . Message , error ) {
func ( s * ResourceGenerator ) makeRoutesForAddresses ( routeName string , addresses map [ string ] string ) ( [ ] proto . Message , error ) {
var resources [ ] proto . Message
var resources [ ] proto . Message
route , err := makeNamedAddressesRoute ( routeName , addresses )
route , err := makeNamedAddressesRoute ( routeName , addresses )
@ -201,7 +200,8 @@ func (s *ResourceGenerator) makeRoutes(
cfgSnap * proxycfg . ConfigSnapshot ,
cfgSnap * proxycfg . ConfigSnapshot ,
svc structs . ServiceName ,
svc structs . ServiceName ,
clusterName string ,
clusterName string ,
autoHostRewrite bool ) ( [ ] proto . Message , error ) {
autoHostRewrite bool ,
) ( [ ] proto . Message , error ) {
resolver , hasResolver := cfgSnap . TerminatingGateway . ServiceResolvers [ svc ]
resolver , hasResolver := cfgSnap . TerminatingGateway . ServiceResolvers [ svc ]
if ! hasResolver {
if ! hasResolver {
@ -255,6 +255,7 @@ func (s *ResourceGenerator) routesForMeshGateway(cfgSnap *proxycfg.ConfigSnapsho
chain ,
chain ,
[ ] string { "*" } ,
[ ] string { "*" } ,
true ,
true ,
perRouteFilterBuilder { } ,
)
)
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -378,7 +379,7 @@ func (s *ResourceGenerator) routesForIngressGateway(cfgSnap *proxycfg.ConfigSnap
}
}
domains := generateUpstreamIngressDomains ( listenerKey , u )
domains := generateUpstreamIngressDomains ( listenerKey , u )
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , domains , false )
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , domains , false , perRouteFilterBuilder { } )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -435,6 +436,7 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
readyUpstreamsList := getReadyListeners ( cfgSnap )
readyUpstreamsList := getReadyListeners ( cfgSnap )
for _ , readyUpstreams := range readyUpstreamsList {
for _ , readyUpstreams := range readyUpstreamsList {
readyUpstreams := readyUpstreams
listenerCfg := readyUpstreams . listenerCfg
listenerCfg := readyUpstreams . listenerCfg
// Do not create any route configuration for TCP listeners
// Do not create any route configuration for TCP listeners
if listenerCfg . Protocol != structs . ListenerProtocolHTTP {
if listenerCfg . Protocol != structs . ListenerProtocolHTTP {
@ -461,12 +463,13 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
// specific naming convention in discoverychain.consolidateHTTPRoutes. If we don't
// specific naming convention in discoverychain.consolidateHTTPRoutes. If we don't
// convert our route to use the same naming convention, we won't find any chains below.
// convert our route to use the same naming convention, we won't find any chains below.
reformatedRoutes := discoverychain . ReformatHTTPRoute ( route , & listenerCfg , cfgSnap . APIGateway . GatewayConfig )
reformatedRoutes := discoverychain . ReformatHTTPRoute ( route , & listenerCfg , cfgSnap . APIGateway . GatewayConfig )
filterBuilder := perRouteFilterBuilder { providerMap : cfgSnap . JWTProviders , listener : & listenerCfg , route : route }
for _ , reformatedRoute := range reformatedRoutes {
for _ , reformatedRoute := range reformatedRoutes {
reformatedRoute := reformatedRoute
reformatedRoute := reformatedRoute
upstream := buildHTTPRouteUpstream ( reformatedRoute , listenerCfg )
upstream := buildHTTPRouteUpstream ( reformatedRoute , listenerCfg )
uid := proxycfg . NewUpstreamID ( & upstream )
uid := proxycfg . NewUpstreamID ( & upstream )
chain := cfgSnap . APIGateway . DiscoveryChain [ uid ]
chain := cfgSnap . APIGateway . DiscoveryChain [ uid ]
if chain == nil {
if chain == nil {
// Note that if we continue here we must also do this in the cluster generation
// Note that if we continue here we must also do this in the cluster generation
@ -476,7 +479,7 @@ func (s *ResourceGenerator) routesForAPIGateway(cfgSnap *proxycfg.ConfigSnapshot
domains := generateUpstreamAPIsDomains ( listenerKey , upstream , reformatedRoute . Hostnames )
domains := generateUpstreamAPIsDomains ( listenerKey , upstream , reformatedRoute . Hostnames )
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , domains , false )
virtualHost , err := s . makeUpstreamRouteForDiscoveryChain ( cfgSnap , uid , chain , domains , false , filterBuilder )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -605,6 +608,7 @@ func (s *ResourceGenerator) makeUpstreamRouteForDiscoveryChain(
chain * structs . CompiledDiscoveryChain ,
chain * structs . CompiledDiscoveryChain ,
serviceDomains [ ] string ,
serviceDomains [ ] string ,
forMeshGateway bool ,
forMeshGateway bool ,
filterBuilder perRouteFilterBuilder ,
) ( * envoy_route_v3 . VirtualHost , error ) {
) ( * envoy_route_v3 . VirtualHost , error ) {
routeName := uid . EnvoyID ( )
routeName := uid . EnvoyID ( )
var routes [ ] * envoy_route_v3 . Route
var routes [ ] * envoy_route_v3 . Route
@ -624,6 +628,7 @@ func (s *ResourceGenerator) makeUpstreamRouteForDiscoveryChain(
routes = make ( [ ] * envoy_route_v3 . Route , 0 , len ( startNode . Routes ) )
routes = make ( [ ] * envoy_route_v3 . Route , 0 , len ( startNode . Routes ) )
for _ , discoveryRoute := range startNode . Routes {
for _ , discoveryRoute := range startNode . Routes {
discoveryRoute := discoveryRoute
routeMatch := makeRouteMatchForDiscoveryRoute ( discoveryRoute )
routeMatch := makeRouteMatchForDiscoveryRoute ( discoveryRoute )
var (
var (
@ -688,8 +693,13 @@ func (s *ResourceGenerator) makeUpstreamRouteForDiscoveryChain(
}
}
}
}
filter , err := filterBuilder . buildTypedPerFilterConfig ( routeMatch , routeAction )
if err != nil {
return nil , err
}
route . Match = routeMatch
route . Match = routeMatch
route . Action = routeAction
route . Action = routeAction
route . TypedPerFilterConfig = filter
routes = append ( routes , route )
routes = append ( routes , route )
}
}