{{- if .Values.deployments.backupOperator }}
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "etcd-backup-operator.fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: {{ template "etcd-backup-operator.name" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  selector:
    matchLabels:
      app: {{ template "etcd-backup-operator.fullname" . }}
      release: {{ .Release.Name }}
  replicas: {{ .Values.backupOperator.replicaCount }}
  template:
    metadata:
      name: {{ template "etcd-backup-operator.fullname" . }}
      labels:
        app: {{ template "etcd-backup-operator.fullname" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ template "etcd-backup-operator.serviceAccountName" . }}
      containers:
      - name: {{ .Values.backupOperator.name }}
        image: "{{ .Values.backupOperator.image.repository }}:{{ .Values.backupOperator.image.tag }}"
        imagePullPolicy: {{ .Values.backupOperator.image.pullPolicy }}
        command:
        - etcd-backup-operator
{{- range $key, $value := .Values.backupOperator.commandArgs }}
        - "--{{ $key }}={{ $value }}"
{{- end }}
        env:
        - name: MY_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        resources:
          limits:
            cpu: {{ .Values.backupOperator.resources.cpu }}
            memory: {{ .Values.backupOperator.resources.memory }}
          requests:
            cpu: {{ .Values.backupOperator.resources.cpu }}
            memory: {{ .Values.backupOperator.resources.memory }}
    {{- if .Values.backupOperator.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.backupOperator.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.backupOperator.tolerations }}
      tolerations:
{{ toYaml .Values.backupOperator.tolerations | indent 8 }}
    {{- end }}
{{- end }}
