apiVersion: apps/v1
kind: Deployment
metadata:
  labels: {{- include "longhorn.labels" . | nindent 4 }}
    app: longhorn-recovery-backend
  name: longhorn-recovery-backend
  namespace: {{ include "release_namespace" . }}
spec:
  replicas: {{ .Values.longhornRecoveryBackend.replicas }}
  selector:
    matchLabels:
      app: longhorn-recovery-backend
  template:
    metadata:
      labels: {{- include "longhorn.labels" . | nindent 8 }}
        app: longhorn-recovery-backend
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - longhorn-recovery-backend
              topologyKey: kubernetes.io/hostname
      containers:
      - name: longhorn-recovery-backend
        image: {{ template "registry_url" . }}{{ .Values.image.longhorn.manager.repository }}:{{ .Values.image.longhorn.manager.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        securityContext:
          runAsUser: 2000
        command:
        - longhorn-manager
        - recovery-backend
        - --service-account
        - longhorn-service-account
        ports:
        - containerPort: 9600
          name: recov-backend
        readinessProbe:
          tcpSocket:
            port: 9600
          initialDelaySeconds: 3
          periodSeconds: 5
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
      {{- if .Values.privateRegistry.registrySecret }}
      imagePullSecrets:
      - name: {{ .Values.privateRegistry.registrySecret }}
      {{- end }}
      {{- if .Values.longhornRecoveryBackend.priorityClass }}
      priorityClassName: {{ .Values.longhornRecoveryBackend.priorityClass | quote }}
      {{- end }}
      {{- if or .Values.longhornRecoveryBackend.tolerations .Values.global.cattle.windowsCluster.enabled }}
      tolerations:
        {{- if and .Values.global.cattle.windowsCluster.enabled .Values.global.cattle.windowsCluster.tolerations }}
{{ toYaml .Values.global.cattle.windowsCluster.tolerations | indent 6 }}
        {{- end }}
        {{- if .Values.longhornRecoveryBackend.tolerations }}
{{ toYaml .Values.longhornRecoveryBackend.tolerations | indent 6 }}
        {{- end }}
      {{- end }}
      {{- if or .Values.longhornRecoveryBackend.nodeSelector .Values.global.cattle.windowsCluster.enabled }}
      nodeSelector:
        {{- if and .Values.global.cattle.windowsCluster.enabled .Values.global.cattle.windowsCluster.nodeSelector }}
{{ toYaml .Values.global.cattle.windowsCluster.nodeSelector | indent 8 }}
        {{- end }}
        {{- if .Values.longhornRecoveryBackend.nodeSelector }}
{{ toYaml .Values.longhornRecoveryBackend.nodeSelector | indent 8 }}
        {{- end }}
      {{- end }}
      serviceAccountName: longhorn-service-account
