apiVersion: apps/v1
kind: DaemonSet
metadata:
  {{- with (include "prometheus-fail2ban-exporter.daemonSet.annotations" . | fromYaml) }}
  annotations:
    {{- tpl (toYaml .) $ | nindent 4 }}
  {{- end }}
  {{- with (include "prometheus-fail2ban-exporter.daemonSet.labels" . | fromYaml) }}
  labels:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  name: {{ include "prometheus-fail2ban-exporter.fullname" . }}
  namespace: {{ .Release.Namespace }}
spec:
  selector:
    matchLabels:
      {{- include "prometheus-fail2ban-exporter.pod.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        {{- include "prometheus-fail2ban-exporter.pod.annotations" . | nindent 8 }}
      labels:
        {{- include "prometheus-fail2ban-exporter.pod.labels" . | nindent 8 }}
    spec:
      {{- with .Values.daemonSet.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: fail2ban-exporter
        args:
        # - "--web.config.file=/etc/prometheus-fail2ban-exporter/config.d/webConfig.yaml"
        - "--web.listen-address=:9191"
        {{- range .Values.daemonSet.fail2banExporter.args }}
        - {{ . | quote }}
        {{- end }}
        {{- $env := (include "prometheus-fail2ban-exporter.daemonSet.env" . | fromYaml) }}
        {{- if and (hasKey $env "env") (gt (len $env.env) 0) }}
        env:
        {{- toYaml $env.env | nindent 8 }}
        {{- end }}
        {{- with .Values.daemonSet.fail2banExporter.envFrom }}
        envFrom:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        image: {{ include "prometheus-fail2ban-exporter.daemonSet.images.fail2ban-exporter.fqin" . | quote }}
        imagePullPolicy: {{ .Values.daemonSet.fail2banExporter.image.pullPolicy }}
        livenessProbe:
          tcpSocket:
            port: 9191
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 3
        readinessProbe:
          tcpSocket:
            port: 9191
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 15
          successThreshold: 1
          timeoutSeconds: 3
        ports:
        - name: http
          containerPort: 9191
          protocol: TCP
        {{- with .Values.daemonSet.fail2banExporter.resources }}
        resources:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        {{- with .Values.daemonSet.fail2banExporter.securityContext }}
        securityContext:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        {{- $volumeMounts := (include "prometheus-fail2ban-exporter.daemonSet.volumeMounts" . | fromYaml) }}
        {{- if hasKey $volumeMounts "volumeMounts" }}
        volumeMounts:
        {{- toYaml $volumeMounts.volumeMounts | nindent 8 }}
        {{- end }}
      {{- with .Values.daemonSet.dnsConfig }}
      dnsConfig:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.daemonSet.dnsPolicy }}
      dnsPolicy: {{ .Values.daemonSet.dnsPolicy }}
      {{- end }}
      {{- if .Values.daemonSet.hostname }}
      hostname: {{ .Values.daemonSet.hostname }}
      {{- end }}
      hostNetwork: {{ .Values.daemonSet.hostNetwork }}
      {{- with .Values.daemonSet.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.daemonSet.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.daemonSet.priorityClassName }}
      priorityClassName: {{ .Values.daemonSet.priorityClassName }}
      {{- end }}
      {{- if .Values.daemonSet.restartPolicy }}
      restartPolicy: {{ .Values.daemonSet.restartPolicy }}
      {{- end }}
      {{- with .Values.daemonSet.securityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccount: {{ include "prometheus-fail2ban-exporter.daemonSet.serviceAccount" . }}
      {{- if .Values.daemonSet.subdomain }}
      subdomain: {{ .Values.daemonSet.subdomain }}
      {{- end }}
      terminationGracePeriodSeconds: {{ .Values.daemonSet.terminationGracePeriodSeconds }}
      {{- with .Values.daemonSet.tolerations }}
      tolerations:
      {{- toYaml . | nindent 6 }}
      {{- end }}
      {{- with .Values.daemonSet.topologySpreadConstraints }}
      topologySpreadConstraints:
      {{- toYaml . | nindent 6 }}
      {{- end }}
      {{- $volumes := (include "prometheus-fail2ban-exporter.daemonSet.volumes" . | fromYaml) }}
      {{- if hasKey $volumes "volumes" }}
      volumes:
      {{- toYaml $volumes.volumes | nindent 6 }}
      {{- end }}
  {{- with .Values.daemonSet.updateStrategy }}
  updateStrategy:
    {{- toYaml . | nindent 4 }}
  {{- end }}