apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "traefik.fullname" . }}
  labels:
    app: {{ template "traefik.name" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
data:
  traefik.toml: |
    # traefik.toml
    {{- if .Values.debug.enabled }}
    debug = true
    {{- else }}
    logLevel = "INFO"
    {{- end }}
    {{- if .Values.sendAnonymousUsage }}
    sendAnonymousUsage = true
    {{- end }}
    {{- if .Values.rootCAs }}
    {{ template "traefik.rootCAs" . }}
    {{- end }}
    {{- if .Values.ssl.insecureSkipVerify }}
    InsecureSkipVerify = true
    {{- end }}
    {{- if .Values.ssl.enabled }}
    defaultEntryPoints = ["http","https"]
    {{- else }}
    defaultEntryPoints = ["http", "httpn"]
    {{- end }}
    [entryPoints]
      [entryPoints.http]
      address = ":80"
      compress = {{ .Values.gzip.enabled }}
      {{- if .Values.whiteListSourceRange }}
      {{ template "traefik.whiteListSourceRange" . }}
      {{- end }}
      {{- if .Values.proxyProtocol.enabled }}
        [entryPoints.http.proxyProtocol]
        {{ template "traefik.trustedips" . }}
      {{- end }}
      {{- if .Values.forwardedHeaders.enabled }}
        [entryPoints.http.forwardedHeaders]
        {{ template "traefik.forwardedHeadersTrustedIPs" . }}
      {{- end }}
        {{- if .Values.ssl.enforced }}
        [entryPoints.http.redirect]
          regex = "^http://(.*)"
          replacement = "https://$1"
          {{- if .Values.ssl.permanentRedirect }}
          permanent = true
          {{- end }}
        {{- end }}
      {{- if .Values.ssl.enabled }}
      [entryPoints.https]
      {{- if .Values.whiteListSourceRange }}
      {{ template "traefik.whiteListSourceRange" . }}
      {{- end }}
      address = ":443"
      compress = {{ .Values.gzip.enabled }}
      {{- if .Values.proxyProtocol.enabled }}
        [entryPoints.https.proxyProtocol]
        {{ template "traefik.trustedips" . }}
      {{- end }}
      {{- if .Values.forwardedHeaders.enabled }}
        [entryPoints.https.forwardedHeaders]
        {{ template "traefik.forwardedHeadersTrustedIPs" . }}
      {{- end }}
      {{- if not .Values.ssl.upstream }}
        [entryPoints.https.tls]
          {{- if .Values.ssl.tlsMinVersion }}
          minVersion = {{ .Values.ssl.tlsMinVersion | quote }}
          {{- end }}
          {{- if .Values.ssl.cipherSuites }}
          {{ template "traefik.ssl.cipherSuites" . }}
          {{- end }}
          [[entryPoints.https.tls.certificates]]
          CertFile = "/ssl/tls.crt"
          KeyFile = "/ssl/tls.key"
      {{- end }}
        {{- if .Values.ssl.auth }}
        {{- if .Values.ssl.auth.basic }}
        [entryPoints.https.auth]
          [entryPoints.https.auth.basic]
            users = [{{ range $key, $value := .Values.ssl.auth.basic }}"{{ $key }}:{{ $value }}",{{ end }}]
        {{- end }}
        {{- end }}
      {{- else }}
      [entryPoints.httpn]
      {{- if .Values.whiteListSourceRange }}
      {{ template "traefik.whiteListSourceRange" . }}
      {{- end }}
      address = ":8880"
      compress = {{ .Values.gzip.enabled }}
      {{- if .Values.proxyProtocol.enabled }}
        [entryPoints.httpn.proxyProtocol]
        {{ template "traefik.trustedips" . }}
      {{- end }}
      {{- if .Values.forwardedHeaders.enabled }}
        [entryPoints.httpn.forwardedHeaders]
        {{ template "traefik.forwardedHeadersTrustedIPs" . }}
      {{- end }}
      {{- end }}
      {{- if .Values.dashboard.enabled }}
      [entryPoints.traefik]
      address = ":8080"
        {{- if .Values.dashboard.auth }}
        {{- if .Values.dashboard.auth.basic }}
        [entryPoints.traefik.auth]
          [entryPoints.traefik.auth.basic]
            users = [{{ range $key, $value := .Values.dashboard.auth.basic }}"{{ $key }}:{{ $value }}",{{ end }}]
        {{- end }}
        {{- end }}
      {{- end }}
    [kubernetes]
    {{- if .Values.kubernetes}}
      {{- if .Values.kubernetes.endpoint }}
    endpoint = {{ .Values.kubernetes.endpoint | quote }}
      {{- end}}
      {{- if .Values.kubernetes.namespaces }}
    namespaces = [
        {{- range $idx, $element := .Values.kubernetes.namespaces }}
            {{- if $idx }}, {{ end }}
            {{- $element | quote }}
        {{- end -}}
        ]
      {{- end}}
      {{- if .Values.kubernetes.labelSelector }}
    labelselector = {{ .Values.kubernetes.labelSelector | quote }}
      {{- end}}
      {{- if .Values.kubernetes.ingressClass }}
    ingressClass = {{ .Values.kubernetes.ingressClass | quote }}
      {{- end}}
      {{- if .Values.kubernetes.ingressEndpoint }}
      [kubernetes.ingressEndpoint]
        {{- if .Values.kubernetes.ingressEndpoint.hostname }}
      hostname = {{ .Values.kubernetes.ingressEndpoint.hostname | quote }}
        {{- end}}
        {{- if .Values.kubernetes.ingressEndpoint.ip }}
      ip = {{ .Values.kubernetes.ingressEndpoint.ip | quote }}
        {{- end}}
        {{- if .Values.kubernetes.ingressEndpoint.publishedService }}
      publishedService = {{ .Values.kubernetes.ingressEndpoint.publishedService | quote }}
        {{- else if .Values.kubernetes.ingressEndpoint.useDefaultPublishedService }}
      publishedService = "{{ .Release.Namespace }}/{{ template "traefik.fullname" . }}"
        {{- end}}
      {{- end}}
    {{- end}}
    {{- if .Values.traefikLogFormat }}
    [traefikLog]
      format = {{ .Values.traefikLogFormat | quote }}
    {{- end }}
    {{- if .Values.accessLogs.enabled }}
    [accessLog]
    {{- if .Values.accessLogs.filePath }}
    filePath = {{ .Values.accessLogs.filePath | quote }}
    {{- end}}
      format = {{ .Values.accessLogs.format | quote }}
    [accessLog.fields]
      defaultMode = {{ .Values.accessLogs.fields.defaultMode | quote }}
    [accessLog.fields.names]
    {{- range $field, $action := .Values.accessLogs.fields.names }}
      {{ printf "\"%s\" = \"%s\"" $field $action }}
    {{- end}}
    [accessLog.fields.headers]
      defaultMode = {{ .Values.accessLogs.fields.headers.defaultMode | quote }}
    [accessLog.fields.headers.names]
    {{- range $header, $action := .Values.accessLogs.fields.headers.names }}
      {{ printf "\"%s\" = \"%s\"" $header $action }}
    {{- end}}
    {{- end}}
    {{- if .Values.kvprovider.etcd }}
    [etcd]
    endpoint = {{ .Values.kvprovider.etcd.endpoint | quote }}
    watch = {{ .Values.kvprovider.etcd.watch }}
    prefix = {{ .Values.kvprovider.etcd.prefix | quote }}
    useAPIV3 = {{ .Values.kvprovider.etcd.useAPIV3 }}
    {{- if .Values.kvprovider.etcd.username }}username = {{ .Values.kvprovider.etcd.username }}{{- end }}
    {{- if .Values.kvprovider.etcd.password }}password = {{ .Values.kvprovider.etcd.password }}{{- end }}
      {{- if .Values.kvprovider.etcd.tls }}
      [etcd.tls]
      {{- end }}
      {{ range $key, $value := .Values.kvprovider.etcd.tls }}
      {{ $key }} = {{ $value | quote }}
      {{ end }}
    {{- end }}
    {{- if .Values.kvprovider.consul }}
    [consul]
    endpoint = {{ .Values.kvprovider.consul.endpoint | quote }}
    watch = {{ .Values.kvprovider.consul.watch }}
    prefix = {{ .Values.kvprovider.consul.prefix | quote }}
    {{- if .Values.kvprovider.consul.username }}username = {{ .Values.kvprovider.consul.username | quote }}{{- end }}
    {{- if .Values.kvprovider.consul.password }}password = {{ .Values.kvprovider.consul.password | quote  }}{{- end }}
      {{- if .Values.kvprovider.consul.tls }}
      [consul.tls]
      {{- end }}
      {{ range $key, $value := .Values.kvprovider.consul.tls }}
      {{ $key }} = {{ $value | quote }}
      {{ end }}
    {{- end }}
    {{- if .Values.kvprovider.boltdb }}
    [boltdb]
    endpoint = {{ .Values.kvprovider.boltdb.endpoint | quote }}
    watch = {{ .Values.kvprovider.boltdb.watch }}
    prefix = {{ .Values.kvprovider.boltdb.prefix }}
    {{- if .Values.kvprovider.boltdb.username }}username = {{ .Values.kvprovider.boltdb.username }}{{- end }}
    {{- if .Values.kvprovider.boltdb.password }}password = {{ .Values.kvprovider.boltdb.password }}{{- end }}
      {{- if .Values.kvprovider.boltdb.tls }}
      [boltdb.tls]
      {{- end }}
      {{ range $key, $value := .Values.kvprovider.boltdb.tls }}
      {{ $key }} = {{ $value }}
      {{ end }}
    {{- end }}
    {{- if .Values.kvprovider.zookeeper }}
    [zookeeper]
    endpoint = {{ .Values.kvprovider.zookeeper.endpoint | quote }}
    watch = {{ .Values.kvprovider.zookeeper.watch }}
    prefix = {{ .Values.kvprovider.zookeeper.prefix | quote }}
    {{- if .Values.kvprovider.zookeeper.username }}username = {{ .Values.kvprovider.zookeeper.username }}{{- end }}
    {{- if .Values.kvprovider.zookeeper.password }}password = {{ .Values.kvprovider.zookeeper.password }}{{- end }}
      {{- if .Values.kvprovider.zookeeper.tls }}
      [zookeeper.tls]
      {{- end }}
      {{ range $key, $value := .Values.kvprovider.zookeeper.tls }}
      {{ $key }} = {{ $value }}
      {{ end }}
    {{- end }}
    {{- if .Values.acme.enabled }}
    [acme]
    email = {{ .Values.acme.email | quote }}
    {{- if .Values.kvprovider.storeAcme }}
    storage = "traefik/acme/account"
    {{- if .Values.kvprovider.importAcme }}
    storageFile = "/acme/acme.json"
    {{- end }}
    {{- if or (.Values.kvprovider.importAcme) (eq .Release.Revision 1) }}
    OverrideCertificates = true
    {{- end }}
    {{- else }}
    storage = "/acme/acme.json"
    {{- end }}
    entryPoint = "https"
    onHostRule = {{ .Values.acme.onHostRule }}
    {{- if .Values.acme.staging }}
    caServer = "https://acme-staging-v02.api.letsencrypt.org/directory"
    {{- end }}
    {{- if .Values.acme.logging }}
    acmeLogging = true
    {{- end }}
    {{- if eq .Values.acme.challengeType "dns-01" }}
      [acme.dnsChallenge]
      provider = {{ .Values.acme.dnsProvider.name | quote }}
      {{- if .Values.acme.delayBeforeCheck }}
      delayBeforeCheck = {{ .Values.acme.delayBeforeCheck }}
      {{- end }}
    {{- else if eq .Values.acme.challengeType "http-01" }}
      [acme.httpChallenge]
      entryPoint = "http"
    {{- else if eq .Values.acme.challengeType "tls-alpn-01" }}
      [acme.tlsChallenge]
    {{- end }}
    {{- if .Values.acme.domains.enabled }}
    {{- if .Values.acme.domains.domainsList }}{{ template "traefik.acme.domains" . }}{{- end }}
    {{- end }}
    {{- end }}
    {{- if .Values.dashboard.enabled }}
    [api]
      entryPoint = "traefik"
      dashboard = true
      {{- if .Values.dashboard.statistics }}
      {{- if .Values.dashboard.statistics.recentErrors }}
      [api.statistics]
        recentErrors = {{ .Values.dashboard.statistics.recentErrors }}
      {{- end }}
      {{- end }}
    {{- end }}
    {{- if or .Values.metrics.prometheus.enabled .Values.metrics.statsd.enabled .Values.metrics.datadog.enabled }}
    [metrics]
    {{- end }}
      {{- if .Values.metrics.prometheus.enabled }}
      [metrics.prometheus]
        entryPoint = "traefik"
        {{- if .Values.metrics.prometheus.buckets }}
        buckets = [
          {{- range $idx, $element := .Values.metrics.prometheus.buckets }}
              {{- if $idx }},{{ end }}
              {{- printf "%.1f" $element }}
          {{- end -}}
          ]
        {{- end -}}
      {{- end }}
      {{- if .Values.metrics.datadog.enabled }}
      [metrics.datadog]
        {{- if .Values.metrics.datadog.address }}
        address = {{ .Values.metrics.datadog.address | quote }}
        {{- end}}
        {{- if .Values.metrics.datadog.pushinterval }}
        pushinterval = {{ .Values.metrics.datadog.pushinterval | quote }}
        {{- end}}
      {{- end }}
      {{- if .Values.metrics.statsd.enabled }}
      [metrics.statsd]
        {{- if .Values.metrics.statsd.address }}
        address = {{ .Values.metrics.statsd.address | quote }}
        {{- end}}
        {{- if .Values.metrics.statsd.pushinterval }}
        pushinterval = {{ .Values.metrics.statsd.pushinterval | quote }}
        {{- end}}
      {{- end }}
    {{- if .Values.tracing.enabled }}
    [tracing]
      backend = {{ .Values.tracing.backend | quote }}
      serviceName = {{ .Values.tracing.serviceName | quote}}
      {{- if eq .Values.tracing.backend "jaeger" }}
      [tracing.jaeger]
        {{- if .Values.tracing.jaeger.localAgentHostPort }}
        localAgentHostPort = {{ .Values.tracing.jaeger.localAgentHostPort | quote }}
        {{- end }}
        {{- if .Values.tracing.jaeger.samplingServerUrl }}
        samplingServerUrl = {{ .Values.tracing.jaeger.samplingServerUrl | quote }}
        {{- end }}
        {{- if .Values.tracing.jaeger.samplingType }}
        samplingType = {{ .Values.tracing.jaeger.samplingType | quote }}
        {{- end }}
        {{- if ne (.Values.tracing.jaeger.samplingParam | quote) "" }}
        samplingParam = {{ .Values.tracing.jaeger.samplingParam }}
        {{- end }}
      {{- end }}
      {{- if eq .Values.tracing.backend "zipkin" }}
      [tracing.zipkin]
        {{- if .Values.tracing.zipkin.httpEndpoint }}
        httpEndpoint = {{ .Values.tracing.zipkin.httpEndpoint | quote }}
        {{- end }}
        {{- if ne (.Values.tracing.zipkin.debug | quote) "" }}
        debug = {{ .Values.tracing.zipkin.debug }}
        {{- end }}
        {{- if ne (.Values.tracing.zipkin.sameSpan | quote) "" }}
        sameSpan = {{ .Values.tracing.zipkin.sameSpan }}
        {{- end }}
        {{- if ne (.Values.tracing.zipkin.id128bit | quote) "" }}
        id128bit = {{ .Values.tracing.zipkin.id128bit }}
        {{- end }}
      {{- end }}
      {{- if eq .Values.tracing.backend "datadog" }}
      [tracing.datadog]
        {{- if .Values.tracing.datadog.localAgentHostPort }}
        localAgentHostPort = {{ .Values.tracing.datadog.localAgentHostPort | quote }}
        {{- end }}
        {{- if ne (.Values.tracing.datadog.debug | quote) "" }}
        debug = {{ .Values.tracing.datadog.debug }}
        {{- end }}
        {{- if ne (.Values.tracing.datadog.globalTag | quote) "" }}
        globalTag = {{ .Values.tracing.datadog.globalTag | quote }}
        {{- end }}
      {{- end }}
    {{- end }}
