@@ -137,9 +137,48 @@ func marshalAny(m proto.Message) *anypb.Any {
137137 return a
138138}
139139
140- // DefaultServerListener returns a basic xds Listener resource to be used on
141- // the server side.
142- func DefaultServerListener (host string , port uint32 , secLevel SecurityLevel ) * v3listenerpb.Listener {
140+ // DefaultServerListener returns a basic xds Listener resource to be used on the
141+ // server side. The returned Listener resource contains an inline route
142+ // configuration with the name of routeName.
143+ func DefaultServerListener (host string , port uint32 , secLevel SecurityLevel , routeName string ) * v3listenerpb.Listener {
144+ return defaultServerListenerCommon (host , port , secLevel , routeName , true )
145+ }
146+
147+ func defaultServerListenerCommon (host string , port uint32 , secLevel SecurityLevel , routeName string , inlineRouteConfig bool ) * v3listenerpb.Listener {
148+ var hcm * v3httppb.HttpConnectionManager
149+ if inlineRouteConfig {
150+ hcm = & v3httppb.HttpConnectionManager {
151+ RouteSpecifier : & v3httppb.HttpConnectionManager_RouteConfig {
152+ RouteConfig : & v3routepb.RouteConfiguration {
153+ Name : routeName ,
154+ VirtualHosts : []* v3routepb.VirtualHost {{
155+ // This "*" string matches on any incoming authority. This is to ensure any
156+ // incoming RPC matches to Route_NonForwardingAction and will proceed as
157+ // normal.
158+ Domains : []string {"*" },
159+ Routes : []* v3routepb.Route {{
160+ Match : & v3routepb.RouteMatch {
161+ PathSpecifier : & v3routepb.RouteMatch_Prefix {Prefix : "/" },
162+ },
163+ Action : & v3routepb.Route_NonForwardingAction {},
164+ }}}}},
165+ },
166+ HttpFilters : []* v3httppb.HttpFilter {RouterHTTPFilter },
167+ }
168+ } else {
169+ hcm = & v3httppb.HttpConnectionManager {
170+ RouteSpecifier : & v3httppb.HttpConnectionManager_Rds {
171+ Rds : & v3httppb.Rds {
172+ ConfigSource : & v3corepb.ConfigSource {
173+ ConfigSourceSpecifier : & v3corepb.ConfigSource_Ads {Ads : & v3corepb.AggregatedConfigSource {}},
174+ },
175+ RouteConfigName : routeName ,
176+ },
177+ },
178+ HttpFilters : []* v3httppb.HttpFilter {RouterHTTPFilter },
179+ }
180+ }
181+
143182 var tlsContext * v3tlspb.DownstreamTlsContext
144183 switch secLevel {
145184 case SecurityLevelNone :
@@ -212,27 +251,8 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
212251 },
213252 Filters : []* v3listenerpb.Filter {
214253 {
215- Name : "filter-1" ,
216- ConfigType : & v3listenerpb.Filter_TypedConfig {
217- TypedConfig : marshalAny (& v3httppb.HttpConnectionManager {
218- RouteSpecifier : & v3httppb.HttpConnectionManager_RouteConfig {
219- RouteConfig : & v3routepb.RouteConfiguration {
220- Name : "routeName" ,
221- VirtualHosts : []* v3routepb.VirtualHost {{
222- // This "*" string matches on any incoming authority. This is to ensure any
223- // incoming RPC matches to Route_NonForwardingAction and will proceed as
224- // normal.
225- Domains : []string {"*" },
226- Routes : []* v3routepb.Route {{
227- Match : & v3routepb.RouteMatch {
228- PathSpecifier : & v3routepb.RouteMatch_Prefix {Prefix : "/" },
229- },
230- Action : & v3routepb.Route_NonForwardingAction {},
231- }}}}},
232- },
233- HttpFilters : []* v3httppb.HttpFilter {RouterHTTPFilter },
234- }),
235- },
254+ Name : "filter-1" ,
255+ ConfigType : & v3listenerpb.Filter_TypedConfig {TypedConfig : marshalAny (hcm )},
236256 },
237257 },
238258 TransportSocket : ts ,
@@ -260,27 +280,8 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
260280 },
261281 Filters : []* v3listenerpb.Filter {
262282 {
263- Name : "filter-1" ,
264- ConfigType : & v3listenerpb.Filter_TypedConfig {
265- TypedConfig : marshalAny (& v3httppb.HttpConnectionManager {
266- RouteSpecifier : & v3httppb.HttpConnectionManager_RouteConfig {
267- RouteConfig : & v3routepb.RouteConfiguration {
268- Name : "routeName" ,
269- VirtualHosts : []* v3routepb.VirtualHost {{
270- // This "*" string matches on any incoming authority. This is to ensure any
271- // incoming RPC matches to Route_NonForwardingAction and will proceed as
272- // normal.
273- Domains : []string {"*" },
274- Routes : []* v3routepb.Route {{
275- Match : & v3routepb.RouteMatch {
276- PathSpecifier : & v3routepb.RouteMatch_Prefix {Prefix : "/" },
277- },
278- Action : & v3routepb.Route_NonForwardingAction {},
279- }}}}},
280- },
281- HttpFilters : []* v3httppb.HttpFilter {RouterHTTPFilter },
282- }),
283- },
283+ Name : "filter-1" ,
284+ ConfigType : & v3listenerpb.Filter_TypedConfig {TypedConfig : marshalAny (hcm )},
284285 },
285286 },
286287 TransportSocket : ts ,
@@ -289,6 +290,13 @@ func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3
289290 }
290291}
291292
293+ // DefaultServerListenerWithRouteConfigName returns a basic xds Listener
294+ // resource to be used on the server side. The returned Listener resource
295+ // contains a RouteCongiguration resource name that needs to be resolved.
296+ func DefaultServerListenerWithRouteConfigName (host string , port uint32 , secLevel SecurityLevel , routeName string ) * v3listenerpb.Listener {
297+ return defaultServerListenerCommon (host , port , secLevel , routeName , false )
298+ }
299+
292300// HTTPFilter constructs an xds HttpFilter with the provided name and config.
293301func HTTPFilter (name string , config proto.Message ) * v3httppb.HttpFilter {
294302 return & v3httppb.HttpFilter {
0 commit comments