{{- if .Values.snapshotController.enabled }}
# This YAML file shows how to deploy the snapshot controller

# The snapshot controller implements the control loop for CSI snapshot functionality.
# It should be installed as part of the base Kubernetes distribution in an appropriate
# namespace for components implementing base system functionality. For installing with
# Vanilla Kubernetes, kube-system makes sense for the namespace.

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: snapshot-controller
  namespace: kube-system
  labels:
    {{- include "kubezero-lib.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.snapshotController.replicas }}
  selector:
    matchLabels:
      app: snapshot-controller
  # the snapshot controller won't be marked as ready if the v1 CRDs are unavailable
  # in #504 the snapshot-controller will exit after around 7.5 seconds if it
  # can't find the v1 CRDs so this value should be greater than that
  minReadySeconds: 15
  strategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: snapshot-controller
    spec:
      affinity:          
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - snapshot-controller
            topologyKey: "kubernetes.io/hostname"
      serviceAccountName: snapshot-controller
      containers:
        - name: snapshot-controller
          image: {{ .Values.snapshotController.image.name }}:{{ .Values.snapshotController.image.tag }}
          args:
            - "--v={{ .Values.snapshotController.logLevel }}"
            {{- if gt (int .Values.snapshotController.replicas) 1 }}
            - "--leader-election=true"
            {{- end }}
            # Add a marker to the snapshot-controller manifests. This is needed to enable feature gates in CSI prow jobs.
            # For example, in https://github.com/kubernetes-csi/csi-release-tools/pull/209, the snapshot-controller YAML is updated to add --prevent-volume-mode-conversion=true so that the feature can be enabled for certain e2e tests.
            # end snapshot controller args
          imagePullPolicy: IfNotPresent
          resources:
            {{- toYaml .Values.snapshotController.resources | nindent 12 }}
      {{- with .Values.snapshotController.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.snapshotController.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}