apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "pihole-exporter.fullname" . }}
  labels:
{{ include "pihole-exporter.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "pihole-exporter.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      {{- with .Values.annotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        app.kubernetes.io/name: {{ include "pihole-exporter.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      automountServiceAccountToken: false
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
          {{- range $key, $value := .Values.extraEnvVars }}
          - name: {{ $key | quote }}
            value: {{ $value | quote }}
          {{- end }}
          {{ if .Values.secretEnvVars }}
          envFrom:
            - secretRef:
                name: {{ include "pihole-exporter.fullname" . }}
          {{- end }}
          ports:
          - name: httpexporter
            containerPort: {{ .Values.service.port }}
            protocol: TCP
          livenessProbe:
            httpGet:
              path: /liveness
              port: {{ .Values.service.port }}
          readinessProbe:
            httpGet:
              path: /readiness
              port: {{ .Values.service.port }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.securityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
