apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "defectdojo.fullname" . }}-celeryworker
  labels:
    app.kubernetes.io/name: {{ include "defectdojo.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "defectdojo.chart" . }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "defectdojo.name" . }}-celeryworker
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "defectdojo.name" . }}-celeryworker
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/managed-by: {{ .Release.Service }}
        helm.sh/chart: {{ include "defectdojo.chart" . }}
    spec:
      containers:
        - command: ["/wait-for-it.sh", '{{ include "defectdojo.fullname" . }}-postgres:5432', "-t", "30", "--", "/entrypoint-celery-worker.sh"]
          env:
            - name: DD_CELERY_BROKER_URL
              value: redis://{{ include "defectdojo.fullname" . }}-redis:6379/0
            - name: DD_CREDENTIAL_AES_256_KEY
              valueFrom:
                secretKeyRef:
                  name: defectdojo-secret
                  key: credential-aes-256-key
            - name: DD_SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: defectdojo-secret
                  key: secret-key
            - name: _DD_DB_USERNAME
              valueFrom:
                secretKeyRef:
                  name: defectdojo-secret
                  key: db-username
            - name: _DD_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: defectdojo-secret
                  key: db-password
            - name: DD_DATABASE_URL
              value: 'postgresql://$(_DD_DB_USERNAME):$(_DD_DB_PASSWORD)@{{ include "defectdojo.fullname" . }}-postgres:5432/defectdojo'
          image: "{{ .Values.djangoImage }}:{{ .Values.djangoTag }}"
          imagePullPolicy: {{ .Values.imagePullPolicy }}
          name: celeryworker
          volumeMounts:
            - mountPath: /app/media
              name: dd-media-pvc
      restartPolicy: Always
      volumes:
        - name: dd-media-pvc
          persistentVolumeClaim:
            claimName: {{ include "defectdojo.fullname" . }}-media
