apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "crrf-daemon.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "crrf-daemon.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "crrf-daemon.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "crrf-daemon.selectorLabels" . | nindent 8 }}
    spec:
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            - ./br
            - operator
            - crr-checkpoint
          args:
            - "--upstream-storage"
            - "{{ .Values.args.upstreamStorage }}"
            {{- if .Values.args.downstreamStorage }}
            - "--downstream-storage"
            - "{{ .Values.args.downstreamStorage }}"
            {{- end }}
            - "--task-name"
            - "{{ .Values.args.taskName }}"
            - "-u"
            - "{{ .Values.args.pdAddr }}"
            - "--status-addr"
            - "{{ .Values.args.statusAddr }}"
            {{- if .Values.tls.enabled }}
            - "--ca"
            - "{{ .Values.tls.mountPath }}/{{ .Values.tls.caFile }}"
            - "--key"
            - "{{ .Values.tls.mountPath }}/{{ .Values.tls.keyFile }}"
            - "--cert"
            - "{{ .Values.tls.mountPath }}/{{ .Values.tls.certFile }}"
            {{- end }}
          env:
            - name: BR_LOG_TO_TERM
              value: "1"
          ports:
            - name: status
              containerPort: 10081
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /status
              port: status
              scheme: HTTPS
            initialDelaySeconds: 10
            periodSeconds: 30
          readinessProbe:
            httpGet:
              path: /status
              port: status
              scheme: HTTPS
            initialDelaySeconds: 5
            periodSeconds: 10
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- if .Values.tls.enabled }}
          volumeMounts:
            - name: client-tls
              mountPath: {{ .Values.tls.mountPath }}
              readOnly: true
          {{- end }}
      {{- if .Values.tls.enabled }}
      volumes:
        - name: client-tls
          secret:
            defaultMode: 420
            secretName: {{ .Values.tls.secretName }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
