# Copyright 2020 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
  name: envoy-conf
data:
  envoy.yaml: |
    static_resources:
      listeners:
      - address:
          socket_address:
            protocol: TCP
            address: 0.0.0.0
            port_value: 8080
        filter_chains:
        - filters:
          - name: envoy.filters.network.http_connection_manager
            typed_config:
              "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
              stat_prefix: ingress_http
              codec_type: AUTO
              route_config:
                name: local_route
                virtual_hosts:
                - name: backend
                  include_request_attempt_count: true
                  domains:
                  - '*'
                  routes:
                  - match:
                      prefix: '/'
                    route:
                      cluster: aggregate_cluster
                      timeout: 30s
                      retry_policy:
                        retry_on: 5xx
                        num_retries: 3
                        per_try_timeout: 10s
              http_filters:
              - name: envoy.filters.http.router
      clusters:
      - name: aggregate_cluster
        connect_timeout: 1s
        lb_policy: CLUSTER_PROVIDED
        cluster_type:
          name: envoy.clusters.aggregate
          typed_config:
            "@type": type.googleapis.com/envoy.config.cluster.aggregate.v2alpha.ClusterConfig
            clusters:
            - pvm
            - std
        circuit_breakers:
          thresholds:
            max_retries: 100
      - name: pvm
        connect_timeout: 1s
        type: STRICT_DNS
        lb_policy: ROUND_ROBIN
        load_assignment:
          cluster_name: pvm
          endpoints:
            lb_endpoints:
            - endpoint:
                address:
                  socket_address:
                    address: web-pvm
                    port_value: 8080
        health_checks:
        - timeout: 1s
          interval: 2s
          unhealthy_threshold: 2
          healthy_threshold: 1
          http_health_check:
            path: "/health"
      - name: std
        connect_timeout: 1s
        type: STRICT_DNS
        lb_policy: ROUND_ROBIN
        load_assignment:
          cluster_name: std
          endpoints:
            lb_endpoints:
            - endpoint:
                address:
                  socket_address:
                    address: web-std
                    port_value: 8080
        health_checks:
        - timeout: 1s
          interval: 10s
          interval_jitter: 10s
          unhealthy_threshold: 2
          healthy_threshold: 1
          http_health_check:
            path: "/health"
    admin:
      access_log_path: "/dev/stdout"
      address:
        socket_address:
          address: 127.0.0.1
          port_value: 8001
