{{- if .Values.backupper.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: backupper
    {{- include "chart.labels" $ | nindent 4 }}
  name: {{ template "chart.fullname" . }}-backupper
  namespace: {{ .Release.Namespace }}
spec:
  replicas: 1
  stragegy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/component: backupper
      {{- include "chart.matchLabels" $ | nindent 6 }}
  template:
    metadata:
      labels:
        app.kubernetes.io/component: backupper
        {{- include "chart.labels" . | nindent 8 }}
      {{- if .Values.backupper.podAnnotations }}
      annotations: {{- toYaml .Values.backupper.podAnnotations | nindent 8 }}
      {{- end }}
    spec:
      {{- if .Values.affinity }}
      affinity: {{- toYaml .Values.affinity | nindent 8 }}
      {{- end }}
      {{- if .Values.global.imagePullSecrets }}
      imagePullSecrets: {{ include "chart.imagePullSecrets" . | trim | nindent 6 }}
      {{- end }}
      containers:
      - name: timebase-backupper
        image: {{ .Values.backupper.image }}
        imagePullPolicy: {{ .Values.backupper.imagePullPolicy }}
        command:
          - sh
          - -c
          - /timebase-server/bin/s3replica.sh -live -timebase $TIMEBASE_URL -streams $STREAMS -bucket $BUCKET -region $REGION
        envFrom:
          - secretRef:
              name: {{ template "chart.fullname" . }}-backupper
          - secretRef:
              name: {{ template "chart.fullname" . }}-server
        env:
        - name: STREAMS
          value: {{ .Values.backupper.streams | join "," }}

{{- end }}
