{{- if .Values.persistence.createStorageClass }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: longhorn-storageclass
  namespace: {{ include "release_namespace" . }}
  labels: {{- include "longhorn.labels" . | nindent 4 }}
data:
  storageclass.yaml: |
    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
      name: longhorn
      annotations:
        storageclass.kubernetes.io/is-default-class: {{ .Values.persistence.defaultClass | quote }}
        {{- range $key, $value := .Values.persistence.annotations }}
        {{ $key }}: {{ $value | quote }}
        {{- end }}
    provisioner: driver.longhorn.io
    allowVolumeExpansion: true
    reclaimPolicy: "{{ .Values.persistence.reclaimPolicy }}"
    volumeBindingMode: {{ .Values.persistence.volumeBindingMode | default "Immediate" }}
    parameters:
      numberOfReplicas: "{{ .Values.persistence.defaultClassReplicaCount }}"
      staleReplicaTimeout: "30"
      fromBackup: ""
      {{- if .Values.persistence.defaultFsType }}
      fsType: "{{ .Values.persistence.defaultFsType }}"
      {{- end }}
      {{- if .Values.persistence.defaultMkfsParams }}
      mkfsParams: "{{ .Values.persistence.defaultMkfsParams }}"
      {{- end }}
      {{- if .Values.persistence.migratable }}
      migratable: "{{ .Values.persistence.migratable }}"
      {{- end }}    
      {{- if .Values.persistence.nfsOptions }}
      nfsOptions: "{{ .Values.persistence.nfsOptions }}"
      {{- end }}    
      {{- if .Values.persistence.backingImage.enable }}
      backingImage: {{ .Values.persistence.backingImage.name }}
      backingImageDataSourceType: {{ .Values.persistence.backingImage.dataSourceType }}
      backingImageDataSourceParameters: {{ .Values.persistence.backingImage.dataSourceParameters }}
      backingImageChecksum: {{ .Values.persistence.backingImage.expectedChecksum }}
      {{- end }}
      {{- if .Values.persistence.recurringJobSelector.enable }}
      recurringJobSelector: '{{ .Values.persistence.recurringJobSelector.jobList }}'
      {{- end }}
      dataLocality: {{ .Values.persistence.defaultDataLocality | quote }}
      {{- if .Values.persistence.defaultDiskSelector.enable }}
      diskSelector: "{{ .Values.persistence.defaultDiskSelector.selector }}"
      {{- end }}
      {{- if .Values.persistence.defaultNodeSelector.enable }}
      nodeSelector: "{{ .Values.persistence.defaultNodeSelector.selector }}"
      {{- end }}
      {{- if .Values.persistence.shareManagerNodeSelector.enable }}
      shareManagerNodeSelector: "{{ .Values.persistence.shareManagerNodeSelector.selector }}"
      {{- end }}
      {{- if .Values.persistence.shareManagerTolerations.enable }}
      shareManagerTolerations: "{{ .Values.persistence.shareManagerTolerations.tolerations }}"
      {{- end }}
      {{- if .Values.persistence.unmapMarkSnapChainRemoved }}
      unmapMarkSnapChainRemoved: "{{ .Values.persistence.unmapMarkSnapChainRemoved }}"
      {{- end }}
      {{- if .Values.persistence.disableRevisionCounter }}
      disableRevisionCounter: "{{ .Values.persistence.disableRevisionCounter }}"
      dataEngine: "{{ .Values.persistence.dataEngine }}"
      {{- end }}
      {{- if .Values.persistence.backupTargetName }}
      backupTargetName: "{{ .Values.persistence.backupTargetName }}"
      {{- end }}
{{- end }}
