apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "quickwit.fullname" . }}
  labels:
    {{- include "quickwit.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "quickwit.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "quickwit.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "quickwit.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      shareProcessNamespace: true
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.healthCheck}}
          {{- .Values.healthCheck | toYaml | nindent 10}}
          {{- end}}
          command:
            - /bin/sh
            - -c
          args:
            - |
              set -x
              ls -laR /quickwit/
              quickwit run --config config/s3-config-listen.yaml
          env:
            - name: AWS_DEFAULT_REGION
              value: "{{ .Values.global.s3.region }}"
            - name: QW_S3_ENDPOINT
              value: '{{ .Values.global.s3.endpoint }}'
            - name: AWS_ACCESS_KEY_ID
              value: {{ .Values.global.s3.accessKey }}
            - name: AWS_SECRET_ACCESS_KEY
              value: {{ .Values.global.s3.secretKey }}
            - name: QW_DATA_DIR
              value: /opt/openreplay/
            {{- range $key, $val := .Values.global.env }}
            - name: {{ $key }}
              value: '{{ $val }}'
            {{- end }}
          ports:
            {{- range $key, $val := .Values.service.ports }}
            - name: {{ $key }}
              containerPort: {{ $val }}
              protocol: TCP
            {{- end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
          - name: configs
            mountPath: /quickwit/config/
          - name: datadir
            mountPath: /opt/openreplay
      volumes:
      - name: configs
        configMap:
          name: {{ include "quickwit.fullname" . }}
      - name: datadir
        emptyDir: {}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
