apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "kubezero-lib.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "kubezero-lib.selectorLabels" . | nindent 6 }}
  serviceName: {{ include "kubezero-lib.fullname" . }}
  template:
    metadata:
      labels:
        {{- include "kubezero-lib.selectorLabels" . | nindent 8 }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
    spec:
      containers:
      - name: clamav
        image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}_{{ .Values.image.type }}"
        ports:
        - containerPort: 3310
          name: clamav
          protocol: TCP
        # Give clamav up to 300s to get CVDs in place etc.
        startupProbe:
          exec:
            command:
            - /usr/local/bin/clamdcheck.sh
          failureThreshold: 30
          periodSeconds: 10
        livenessProbe:
          exec:
            command:
            - /usr/local/bin/clamdcheck.sh
          failureThreshold: 2
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 3
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        volumeMounts:
          - mountPath: /var/lib/clamav
            name: signatures
          - mountPath: /etc/clamav
            name: config-volume
      #securityContext:
      #  runAsNonRoot: true
      volumes:
      - name: config-volume
        configMap:
          name: {{ include "kubezero-lib.fullname" . }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
  volumeClaimTemplates:
  - metadata:
      name: signatures
    spec:
      accessModes: [ "ReadWriteOnce" ]
      {{- with .Values.storageClassName }}
      storageClassName: {{ . }}
      {{- end }}
      resources:
        requests:
          storage: 2Gi
