apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "coredns.fullname" . }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    {{- if .Values.isClusterService }}
    k8s-app: {{ .Chart.Name | quote }}
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "CoreDNS"
    {{- end }}
    app: {{ template "coredns.name" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      release: {{ .Release.Name | quote }}
      {{- if .Values.isClusterService }}
      k8s-app: {{ .Chart.Name | quote }}
      {{- end }}
      app: {{ template "coredns.name" . }}
  template:
    metadata:
      labels:
        {{- if .Values.isClusterService }}
        k8s-app: {{ .Chart.Name | quote }}
        {{- end }}
        app: {{ template "coredns.name" . }}
        release: {{ .Release.Name | quote }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        {{- if .Values.isClusterService }}
        scheduler.alpha.kubernetes.io/critical-pod: ''
        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
        {{- end }}
    spec:
      serviceAccountName: {{ template "coredns.serviceAccountName" . }}
      {{- if .Values.isClusterService }}
      dnsPolicy: Default
      {{- end }}
      {{- if .Values.affinity }}
      affinity:
{{ toYaml .Values.affinity | indent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
      {{- end }}
      containers:
      - name: "coredns"
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        args: [ "-conf", "/etc/coredns/Corefile" ]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/coredns
        resources:
{{ toYaml .Values.resources | indent 10 }}
        ports:
{{ include "coredns.containerPorts" . | indent 8 }}
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
      volumes:
        - name: config-volume
          configMap:
            name: {{ template "coredns.fullname" . }}
            items:
            - key: Corefile
              path: Corefile
            {{ range .Values.zoneFiles }}
            - key: {{ .filename }}
              path: {{ .filename }}
            {{ end }}
