Overview

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:

  • www.example.com/product-1/foo served by app-1
  • www.example.com/product-2/foo served by app-1
  • www.example.com/product-1/bar served by app-2
  • www.example.com/product-2/bar served by app-2

Example YAML configuration files

  # Example of matcher inheritance
# Parent table with two matchers
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: parent
  namespace: source-apps
spec:
  hosts:
    - www.example.com
  virtualGateways:
    - name: istio-ingressgateway
      namespace: gloo-mesh-gateways
  http:
    - 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-a
      delegate:
        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-a
      delegate:
        routeTables:
        - labels:
            table: child-a 
---
# Child A route table
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: child-a
  namespace: target-apps
  labels:
    # Matches label in parent route table to for delegation
    table: child-a
spec:
  http:
  # Table routes matching requests to app-1
  - name: product-1
    matchers:
    - uri:
        prefix: /foo
        ignoreCase: true
    forwardTo:
      destinations:
      - ref:
          name: app-1
          namespace: target-apps
        port:
          number: 8080
        kind: VIRTUAL_DESTINATION
  # Table routes matching requests to app-2
  - name: product-1
    matchers:
    - uri:
        prefix: /bar
        ignoreCase: true
    forwardTo:
      destinations:
      - ref:
          name: app-2
          namespace: target-apps
        port:
          number: 8080
        kind: 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:

  • www.example.com/product-1 served by app-1
  • www.example.com/product-2 served by app-2

Example YAML configuration files

  # Example of matcher inheritance
# Parent table with two matchers
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: parent
  namespace: source-apps
spec:
  hosts:
    - www.example.com
  virtualGateways:
    - name: istio-ingressgateway
      namespace: gloo-mesh-gateways
  http:
    - name: product-1
      # Match requests along the path `www.example.com/product-1`
      matchers:
      - uri:
          prefix: /product-1
          ignoreCase: true
      # Delegate requests that match this path to child-a
      delegate:
        routeTables:
        - labels:
            table: child-a 
    - name: product-1
      # Match requests along the path `www.example.com/product-2`
      matchers:
      - uri:
          prefix: /product-2
          ignoreCase: true
      # Delegate requests that match this path to child-b
      delegate:
        routeTables:
        - labels:
            table: child-b
---
# Child A route table
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: child-a
  namespace: target-apps
  labels:
    # Matches label in parent route table to for delegation
    table: child-a
spec:
  http:
  # Table routes matching requests to app-1
  - name: product-1
    forwardTo:
      destinations:
      - ref:
          name: app-1
          namespace: target-apps
        port:
          number: 8080
        kind: VIRTUAL_DESTINATION
---
# Child B route table
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: child-b
  namespace: target-apps
  labels:
    # Matches label in parent route table to for delegation
    table: child-b
spec:
  http:
  # Table routes matching requests to app-2
  - name: product-2
    forwardTo:
      destinations:
      - ref:
          name: app-2
          namespace: target-apps
        port:
          number: 8080
        kind: VIRTUAL_DESTINATION