Last updated Jan 2, 2025

Adding Type URLs to your resources

Background

Before 1.0.0, upon receiving a discovery request from an envoy proxy and then generating configuration from templates, Sovereign would iterate over every resource, check if it had a type URL, and add it for the resource type if not.

Problems

While convenient, there were some issues with this:

  • The type URLs are hard-coded into Sovereign and might not cover all resource types
  • It makes caching difficult (modifying the generated response before giving it back to envoy)

Solution

Your templates should specify the type URL for each type.

You could either import these type URLs from somewhere using Python templates, or add a mapping of resource type/type URL as a piece of template context.

Example template context

This mapping of type URLs is non-exhaustive. Also note that it gives back type URLs for the v3 API.

1
2
template_context:
  context:
    type_urls:
      protocol: inline
      serialization: yaml
      path: |
        ---
        clusters: type.googleapis.com/envoy.config.cluster.v3.Cluster
        endpoints: type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment
        listeners: type.googleapis.com/envoy.config.listener.v3.Listener
        routes: type.googleapis.com/envoy.config.route.v3.RouteConfiguration
        runtime: type.googleapis.com/envoy.service.runtime.v3.Runtime
        scoped-routes: type.googleapis.com/envoy.config.route.v3.ScopedRouteConfiguration
        secrets: type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.Secret

Example replacement in templates

1
2
def call(discovery_request, items, **kwargs):
    for item in items:
        # if the item can't have properties set, it will need
        # to become a type that is capable of such

        item["@type"] = TYPE_URL # example: type.googleapis.com/envoy.config.listener.v3.Listener
        yield item

If you decided to pass in template context:

1
2
def call(discovery_request, items, type_urls, **kwargs):
    for item in items:
        item["@type"] = type_urls["listeners"]
        yield item

Rate this page: