github.com/projectcontour/contour@v1.28.2/site/content/docs/1.25/config/inclusion-delegation.md (about)

     1  # HTTPProxy Inclusion
     2  
     3  HTTPProxy permits the splitting of a system's configuration into separate HTTPProxy instances using **inclusion**.
     4  
     5  Inclusion, as the name implies, allows for one HTTPProxy object to be included in another, optionally with some conditions inherited from the parent.
     6  Contour reads the inclusion tree and merges the included routes into one big object internally before rendering Envoy config.
     7  Importantly, the included HTTPProxy objects do not have to be in the same namespace.
     8  
     9  Each tree of HTTPProxy starts with a root, the top level object of the configuration for a particular virtual host.
    10  Each root HTTPProxy defines a `virtualhost` key, which describes properties such as the fully qualified name of the virtual host, TLS configuration, etc.
    11  
    12  HTTPProxies included from the root must not contain a virtualhost key.
    13  Root objects cannot include other roots either transitively or directly.
    14  This permits the owner of an HTTPProxy root to allow the inclusion of a portion of the route space inside a virtual host, and to allow that route space to be further subdivided with inclusions.
    15  Because the path is not necessarily used as the only key, the route space can be multi-dimensional.
    16  
    17  ## Conditions and Inclusion
    18  
    19  Like Routes, Inclusion may specify a set of [conditions][1].
    20  These conditions are added to any conditions on the routes included.
    21  This process is recursive.
    22  
    23  Conditions are sets of individual condition statements, for example `prefix: /blog` is the condition that the matching request's path must start with `/blog`.
    24  When conditions are combined through inclusion Contour merges the conditions inherited via inclusion with any conditions specified on the route.
    25  This may result in duplicates, for example two `prefix:` conditions, mix of both `prefix:` and `exact` conditions, or two header match conditions with the same name and value.
    26  To resolve this Contour applies the following logic.
    27  
    28  - `prefix:` conditions are concatenated together in the order they were applied from the root object. For example the conditions, `prefix: /api`, `prefix: /v1` becomes a single `prefix: /api/v1` conditions. Note: Multiple prefixes cannot be supplied on a single set of Route conditions.
    29  - `exact:` conditions are also concatenated just like `prefix:` conditions, but `exact:` conditions are not allowed in include match conditions. If the child httpproxy has `exact:` condition then after concatenation, it becomes a single `exact:` condition. For example, `prefix: /static` and `exact: /main.js` become a single `exact: /static/main.js` condition.
    30  - Proxies with repeated identical `header:` conditions of type "exact match" (the same header keys exactly) are marked as "Invalid" since they create an un-routable configuration.
    31  
    32  ## Configuring Inclusion
    33  
    34  Inclusion is a top-level field in the HTTPProxy [spec][2] element.
    35  It requires one field, `name`, and has two optional fields:
    36  
    37  - `namespace`. This will assume the included HTTPProxy is in the same namespace if it's not specified.
    38  - a `conditions` block.
    39  
    40  ## Inclusion Within the Same Namespace
    41  
    42  HTTPProxies can include other HTTPProxy objects in the namespace by specifying the name of the object and its namespace in the top-level `includes` block.
    43  Note that `includes` is a list, and so it must use the YAML list construct.
    44  
    45  In this example, the HTTPProxy `include-root` has included the configuration for paths matching `/service2` from the HTTPProxy named `service2` in the same namespace as `include-root` (the `default` namespace).
    46  It's important to note that `service2` HTTPProxy has not defined a `virtualhost` property as it is NOT a root HTTPProxy.
    47  
    48  ```yaml
    49  # httpproxy-inclusion-samenamespace.yaml
    50  apiVersion: projectcontour.io/v1
    51  kind: HTTPProxy
    52  metadata:
    53    name: include-root
    54    namespace: default
    55  spec:
    56    virtualhost:
    57      fqdn: root.bar.com
    58    includes:
    59    # Includes the /service2 path from service2 in the same namespace
    60    - name: service2
    61      namespace: default
    62      conditions:
    63      - prefix: /service2
    64    routes:
    65      - conditions:
    66        - prefix: /
    67        services:
    68          - name: s1
    69            port: 80
    70  ---
    71  apiVersion: projectcontour.io/v1
    72  kind: HTTPProxy
    73  metadata:
    74    name: service2
    75    namespace: default
    76  spec:
    77    routes:
    78      - services: # matches /service2
    79          - name: s2
    80            port: 80
    81      - conditions:
    82        - prefix: /blog # matches /service2/blog
    83        services:
    84          - name: blog
    85            port: 80
    86  ```
    87  
    88  ## Inclusion Across Namespaces
    89  
    90  Inclusion can also happen across Namespaces by specifying a `namespace` in the `inclusion`.
    91  This is a particularly powerful paradigm for enabling multi-team Ingress management.
    92  
    93  In this example, the root HTTPProxy has included configuration for paths matching `/blog` to the `blog` HTTPProxy object in the `marketing` namespace.
    94  
    95  ```yaml
    96  # httpproxy-inclusion-across-namespaces.yaml
    97  ---
    98  apiVersion: projectcontour.io/v1
    99  kind: HTTPProxy
   100  metadata:
   101    name: namespace-include-root
   102    namespace: default
   103  spec:
   104    virtualhost:
   105      fqdn: ns-root.bar.com
   106    includes:
   107    # delegate the subpath, `/blog` to the HTTPProxy object in the marketing namespace with the name `blog`
   108    - name: blog
   109      namespace: marketing
   110      conditions:
   111      - prefix: /blog
   112    routes:
   113      - services:
   114          - name: s1
   115            port: 80
   116  
   117  ---
   118  apiVersion: projectcontour.io/v1
   119  kind: HTTPProxy
   120  metadata:
   121    name: blog
   122    namespace: marketing
   123  spec:
   124    routes:
   125      - services:
   126          - name: s2
   127            port: 80
   128  ```
   129  
   130  ## Orphaned HTTPProxy children
   131  
   132  It is possible for HTTPProxy objects to exist that have not been delegated to by another HTTPProxy.
   133  These objects are considered "orphaned" and will be ignored by Contour in determining ingress configuration.
   134  
   135  [1]: request-routing#conditions
   136  [2]: api/#projectcontour.io/v1.HTTPProxySpec