# Jinja2 template for Envoy configuration
admin:
  address:
    socket_address:
      address: 0.0.0.0
      port_value: {{ envoy_admin_port }}

static_resources:
  listeners:
    # Listener for ytdlp-ops Thrift traffic
    - name: ytdlp_ops_listener
      address:
        socket_address:
          address: 0.0.0.0
          port_value: {{ envoy_port }}
      filter_chains:
        - filters:
            - name: envoy.filters.network.thrift_proxy
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.thrift_proxy.v3.ThriftProxy
                stat_prefix: thrift_ingress
                transport: FRAMED
                protocol: BINARY
                route_config:
                  name: local_route
                  routes:
                    - match:
                        method_name: ""
                      route:
                        cluster: ytdlp_ops_cluster

  clusters:
    # Cluster for the ytdlp-ops workers
    - name: ytdlp_ops_cluster
      connect_timeout: 5s
      type: {{ envoy_cluster_type }}
      lb_policy: ROUND_ROBIN
      health_checks:
        - timeout: 1s
          interval: 5s
          unhealthy_threshold: 3
          healthy_threshold: 2
          tcp_health_check: {}
      load_assignment:
        cluster_name: ytdlp_ops_cluster
        endpoints:
          - lb_endpoints:
              {% for i in range(worker_count) %}
              - endpoint:
                  address:
                    socket_address:
                      address: {{ backend_address }}
                      port_value: {{ base_port + i }}
              {% endfor %}
