{{- if .Values.ingestion.enabled }}

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: granule-ingester
  name: granule-ingester
spec:
  replicas: {{ .Values.ingestion.granuleIngester.replicas }}
  selector:
    matchLabels:
      app: granule-ingester
  template:
    metadata:
      labels:
        app: granule-ingester
    spec:
      {{- if .Values.ingestion.granules.s3.serviceAccountName }}
      serviceAccountName: {{ .Values.ingestion.granules.s3.serviceAccountName }}
      {{- end }}
      containers:
        - image: {{ .Values.ingestion.granuleIngester.image }}
          imagePullPolicy: Always
          name: granule-ingester
          env:
            - name: RABBITMQ_USERNAME
              value: {{ .Values.rabbitmq.auth.username }}
            - name: RABBITMQ_PASSWORD
              value: {{ .Values.rabbitmq.auth.password }}
            - name: RABBITMQ_HOST
              value: {{ .Values.rabbitmq.fullnameOverride }}
            - name: CASSANDRA_CONTACT_POINTS
              value: {{ include "nexus.urls.cassandra" . }}
            - name: CASSANDRA_USERNAME
              value: {{ include "nexus.credentials.cassandra.username" . }}
            - name: CASSANDRA_PASSWORD
              value: {{ include "nexus.credentials.cassandra.password" . }}
            - name: ZK_HOST_AND_PORT
              value: {{ include "nexus.urls.zookeeper" . }}
            {{ if .Values.ingestion.granuleIngester.maxConcurrency }}
            - name: MAX_CONCURRENCY
              value: "{{ .Values.ingestion.granuleIngester.maxConcurrency }}"
            {{ end }}
            {{- if not .Values.ingestion.granules.s3.serviceAccountName }}
            {{- range $name, $value := .Values.ingestion.granules.s3.awsCredsEnvs }}
            - name: {{ $name }}
              value: {{ $value }}
            {{- end }}
            {{- end }}
          resources:
            requests:
              cpu: {{ .Values.ingestion.granuleIngester.cpu }}
              memory: {{ .Values.ingestion.granuleIngester.memory }}
            limits:
              cpu: {{ .Values.ingestion.granuleIngester.cpu }}
              memory: {{ .Values.ingestion.granuleIngester.memory }}
          volumeMounts:
{{- if not .Values.ingestion.granules.s3.bucket }}
{{ include "nexus.ingestion.dataVolumeMount" . | indent 12 }}
{{- end }}
      volumes:
{{- if not .Values.ingestion.granules.s3.bucket }}
{{ include "nexus.ingestion.dataVolume" . | indent 8 }}
{{- end }}
      restartPolicy: Always
{{- end }}

