Delegated routes inherit matchers from the parent route table. This way, you can route to specific subpaths that share a common element. Review the following examples of how matcher inheritance works.
Multiple matchers in the same table
Multiple matchers can lead to many matching routes, as shown in the following example.
Say that you have two matchers in a parent route table for the www.example.com host domain: /product-1 and /product-2.
The delegated child route table also has two matchers: /foo and /bar. The /foo matcher routes requests to the app-1 virtual destination. The /bar matcher routes requests to the app-2 virtual destination.
The resulting child routes inherit the parent matchers and can match on the following paths:
# Example of matcher inheritance# Parent table with two matchersapiVersion:networking.gloo.solo.io/v2kind:RouteTablemetadata:name:parentnamespace:source-appsspec:hosts:-www.example.comvirtualGateways:-name:istio-ingressgatewaynamespace:gloo-mesh-gatewayshttp:-name:product-1# Match requests along the path `www.example.com/product-1`matchers:-uri:prefix:/product-1# Delegate requests that match this path to child-adelegate:routeTables:-labels:table:child-a-name:product-1# Match requests along the path `www.example.com/product-2`matchers:-uri:prefix:/product-2# Delegate requests that match this path to child-adelegate:routeTables:-labels:table:child-a---# Child A route tableapiVersion:networking.gloo.solo.io/v2kind:RouteTablemetadata:name:child-anamespace:target-appslabels:# Matches label in parent route table to for delegationtable:child-aspec:http:# Table routes matching requests to app-1-name:product-1matchers:-uri:prefix:/fooignoreCase:trueforwardTo:destinations:-ref:name:app-1namespace:target-appsport:number:8080kind:VIRTUAL_DESTINATION# Table routes matching requests to app-2-name:product-1matchers:-uri:prefix:/barignoreCase:trueforwardTo:destinations:-ref:name:app-2namespace:target-appsport:number:8080kind:VIRTUAL_DESTINATION
Separate child tables without matchers
As you saw in the previous example, multiple matchers can lead to many matching routes. These resulting routes might not be what you intended.
Say that you wanted only two matching routes, /product-1 served by the app-1 virtual destination and /product-2 served by the app-2 virtual destination.
With matcher inheritance, you can configure your parent and child route tables to achieve this scenario. In the parent route table, specify the full matchers for the resulting routes that you want in the parent route table. Each matcher delegates to a seperate child route table. In the child route tables, do not add more matchers. Instead, the child route tables inherit the matchers from the parent. The child route tables specify the apps to route to.
The resulting child routes inherit the parent matchers and can match on the following paths:
# Example of matcher inheritance# Parent table with two matchersapiVersion:networking.gloo.solo.io/v2kind:RouteTablemetadata:name:parentnamespace:source-appsspec:hosts:-www.example.comvirtualGateways:-name:istio-ingressgatewaynamespace:gloo-mesh-gatewayshttp:-name:product-1# Match requests along the path `www.example.com/product-1`matchers:-uri:prefix:/product-1ignoreCase:true# Delegate requests that match this path to child-adelegate:routeTables:-labels:table:child-a-name:product-1# Match requests along the path `www.example.com/product-2`matchers:-uri:prefix:/product-2ignoreCase:true# Delegate requests that match this path to child-bdelegate:routeTables:-labels:table:child-b---# Child A route tableapiVersion:networking.gloo.solo.io/v2kind:RouteTablemetadata:name:child-anamespace:target-appslabels:# Matches label in parent route table to for delegationtable:child-aspec:http:# Table routes matching requests to app-1-name:product-1forwardTo:destinations:-ref:name:app-1namespace:target-appsport:number:8080kind:VIRTUAL_DESTINATION---# Child B route tableapiVersion:networking.gloo.solo.io/v2kind:RouteTablemetadata:name:child-bnamespace:target-appslabels:# Matches label in parent route table to for delegationtable:child-bspec:http:# Table routes matching requests to app-2-name:product-2forwardTo:destinations:-ref:name:app-2namespace:target-appsport:number:8080kind:VIRTUAL_DESTINATION