apiVersion: v1
kind: ConfigMap
metadata:
  name: istio
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ template "istio.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  mesh: |-

  {{- if .Values.global.remotePolicyAddress }}
    # Set the following variable to true to disable policy checks by the Mixer.
    # Note that metrics will still be reported to the Mixer.
    disablePolicyChecks: {{ .Values.global.disablePolicyChecks }}
  {{- end }}  

  {{- if .Values.global.remoteZipkinAddress }}
    # Set enableTracing to false to disable request tracing.
    enableTracing: {{ .Values.global.enableTracing }}
  {{- end }}  

    # TODO: not clear if this is used - pilot generates config based on the main cluster config.
    # Set accessLogFile to empty string to disable access log.
    accessLogFile: "{{ .Values.global.proxy.accessLogFile }}"
    #
    # To disable the mixer completely (including metrics), comment out
    # the following lines
  {{- if .Values.global.remotePolicyAddress }}
    mixerCheckServer: {{ .Values.global.remotePolicyAddress }}:15004
  {{- end }}

  {{- if .Values.global.remoteTelemetryAddress }}
    mixerReportServer: {{ .Values.global.remoteTelemetryAddress }}:15004
  {{- end }}

    defaultConfig:
      #
      # TCP connection timeout between Envoy & the application, and between Envoys.
      connectTimeout: 10s
      #
      ### ADVANCED SETTINGS #############
      # Where should envoy's configuration be stored in the istio-proxy container
      configPath: "/etc/istio/proxy"
      binaryPath: "/usr/local/bin/envoy"
      # The pseudo service name used for Envoy.
      serviceCluster: istio-proxy
      # These settings that determine how long an old Envoy
      # process should be kept alive after an occasional reload.
      drainDuration: 45s
      parentShutdownDuration: 1m0s
      #
      # The mode used to redirect inbound connections to Envoy. This setting
      # has no effect on outbound traffic: iptables REDIRECT is always used for
      # outbound connections.
      # If "REDIRECT", use iptables REDIRECT to NAT and redirect to Envoy.
      # The "REDIRECT" mode loses source addresses during redirection.
      # If "TPROXY", use iptables TPROXY to redirect to Envoy.
      # The "TPROXY" mode preserves both the source and destination IP
      # addresses and ports, so that they can be used for advanced filtering
      # and manipulation.
      # The "TPROXY" mode also configures the sidecar to run with the
      # CAP_NET_ADMIN capability, which is required to use TPROXY.
      #interceptionMode: REDIRECT
      #
      # Port where Envoy listens (on local host) for admin commands
      # You can exec into the istio-proxy container in a pod and
      # curl the admin port (curl http://localhost:15000/) to obtain
      # diagnostic information from Envoy. See
      # https://lyft.github.io/envoy/docs/operations/admin.html
      # for more details
      proxyAdminPort: 15000

    {{- if .Values.global.remoteZipkinAddress }}
      #
      # Zipkin trace collector
      zipkinAddress: {{ .Values.global.remoteZipkinAddress }}:9411
    {{- end }}

    {{- if .Values.global.proxy.envoyStatsd.enabled }}
      #
      # Statsd metrics collector converts statsd metrics into Prometheus metrics.
      statsdUdpAddress: {{ .Values.global.proxy.envoyStatsd.host }}:{{ .Values.global.proxy.envoyStatsd.port }}
    {{- end }}

    {{- $defPilotHostname := printf "istio-pilot.%s" .Release.Namespace }}
    {{- $pilotAddress := .Values.global.remotePilotAddress | default $defPilotHostname }}
    {{- if .Values.global.controlPlaneSecurityEnabled }}
      #
      # Mutual TLS authentication between sidecars and istio control plane.
      controlPlaneAuthPolicy: MUTUAL_TLS
      #
      # Address where istio Pilot service is running
      {{- if .Values.global.remotePilotCreateSvcEndpoint }}
      discoveryAddress: {{ $defPilotHostname }}:15011
      {{- else }}
      discoveryAddress: {{ $pilotAddress }}:15011
      {{- end }}
    {{- else }}
      #
      # Mutual TLS authentication between sidecars and istio control plane.
      controlPlaneAuthPolicy: NONE
      #
      # Address where istio Pilot service is running
      {{- if .Values.global.remotePilotCreateSvcEndpoint }}
      discoveryAddress: {{ $defPilotHostname }}:15010
      {{- else }}
      discoveryAddress: {{ $pilotAddress }}:15010
      {{- end }}
    {{- end }}
