{{- if .Values.enableVolumeSnapshot }}
#Snapshot controller
kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: ebs-snapshot-controller
  labels:
  {{- include "aws-ebs-csi-driver.labels" . | nindent 4 }}
spec:
  serviceName: ebs-snapshot-controller
  replicas: 1
  selector:
    matchLabels:
      app: ebs-snapshot-controller
      {{- include "aws-ebs-csi-driver.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        app: ebs-snapshot-controller
        {{- include "aws-ebs-csi-driver.labels" . | nindent 8 }}
        {{- if .Values.snapshotController.podLabels }}
        {{- toYaml .Values.snapshotController.podLabels | nindent 8 }}
        {{- end }}
      {{- if .Values.snapshotController.podAnnotations }}
      annotations: {{ toYaml .Values.snapshotController.podAnnotations | nindent 8 }}
      {{- end }}
    spec:
      serviceAccountName: {{ .Values.serviceAccount.snapshot.name }}
      nodeSelector:
        kubernetes.io/os: linux
        {{- with .Values.nodeSelector }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
      priorityClassName: {{ .Values.priorityClassName | default "system-cluster-critical" }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
        - operator: Exists
          effect: NoExecute
          tolerationSeconds: 300
        {{- with .Values.tolerations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      containers:
        - name: snapshot-controller
          image: {{ printf "%s:%s" .Values.snapshotController.repository .Values.snapshotController.tag }}
          {{- with .Values.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- if .Values.proxy.http_proxy }}
          env:
            {{- include "aws-ebs-csi-driver.http-proxy" . | nindent 12 }}
          {{- end }}
          args:
            - --v=2
            - --leader-election=false
      {{- if .Values.imagePullSecrets }}
      imagePullSecrets:
      {{- range .Values.imagePullSecrets }}
        - name: {{ . }}
      {{- end }}
      {{- end }}
{{- end }}