apiVersion: {{ default "apps/v1" .Values.kubeMeta.deploymentApiVersion }}
kind: Deployment
metadata:
  name: {{ include "clamav.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "clamav.name" . }}
    helm.sh/chart: {{ include "clamav.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "clamav.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "clamav.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.freshclamConfig }}
          volumeMounts:
          - name: freshclam-config-volume
            mountPath: /etc/clamav/freshclam.conf
            subPath: freshclam.conf
{{- end }}
{{- if .Values.clamdConfig }}
          volumeMounts:
          - name: clamd-config-volume
            mountPath: /etc/clamav/clamd.conf
            subPath: clamd.conf
{{- end }}
          ports:
            - name: clamavport
              containerPort: 3310
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: clamavport
            initialDelaySeconds: 300
          readinessProbe:
            tcpSocket:
              port: clamavport
            initialDelaySeconds: 300
          resources:
{{ toYaml .Values.resources | indent 12 }}
{{- if .Values.freshclamConfig }}
      volumes:
        - name: freshclam-config-volume
          configMap:
            name: {{ include "clamav.fullname" . }}-freshclam
{{- end }}
{{- if .Values.clamdConfig }}
      volumes:
        - name: clamd-config-volume
          configMap:
            name: {{ include "clamav.fullname" . }}-clamd
{{- end }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
