apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "node-local-dns.fullname" . }}
  namespace: kube-system
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    {{- include "node-local-dns.labels" . | nindent 4 }}
data:
  Corefile: |
    {{- if .Values.config.customConfig -}}
    {{- tpl .Values.config.customConfig . | nindent 4}}
    {{- else }}
    {{ .Values.config.dnsDomain }}:53 {
        errors
        cache {
                success 9984 30
                denial 9984 5
        }
        reload
        loop
    {{- if .Values.config.bindIp }}
        bind {{ .Values.config.localDns }} {{ .Values.config.dnsServer }}
    {{- else }}
        bind 0.0.0.0
    {{- end }}
        forward . __PILLAR__CLUSTER__DNS__ {
                {{ .Values.config.commProtocol }}
        }
        prometheus :9253
        health :{{ .Values.config.healthPort }}
        }
    in-addr.arpa:53 {
        errors
        cache 30
        reload
        loop
    {{- if .Values.config.bindIp }}
        bind {{ .Values.config.localDns }} {{ .Values.config.dnsServer }}
    {{- else }}
        bind 0.0.0.0
    {{- end }}
        forward . __PILLAR__CLUSTER__DNS__ {
                {{ .Values.config.commProtocol }}
        }
        prometheus :9253
        }
    ip6.arpa:53 {
        errors
        cache 30
        reload
        loop
    {{- if .Values.config.bindIp }}
        bind {{ .Values.config.localDns }} {{ .Values.config.dnsServer }}
    {{- else }}
        bind 0.0.0.0
    {{- end }}
        forward . __PILLAR__CLUSTER__DNS__ {
                {{ .Values.config.commProtocol }}
        }
        prometheus :9253
        }
    .:53 {
        errors
        cache 30
        reload
        loop
    {{- if .Values.config.bindIp }}
        bind {{ .Values.config.localDns }} {{ .Values.config.dnsServer }}
    {{- else }}
        bind 0.0.0.0
    {{- end }}
        forward . __PILLAR__UPSTREAM__SERVERS__
        prometheus :9253
        }
    {{ end }}
