apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.configmap.name }}
  namespace: {{ include "local-path-provisioner.namespace" . }}
  labels:
{{ include "local-path-provisioner.labels" . | indent 4 }}
data:
  config.json: |-
    {{- $config := dict }}
    {{- with .Values.nodePathMap }}
    {{- $config = set $config "nodePathMap" . }}
    {{- end }}
    {{- with .Values.sharedFileSystemPath }}
    {{- $config = set $config "sharedFileSystemPath" . }}
    {{- end }}
    {{- with .Values.storageClassConfigs }}
    {{- $configs := dict }}
    {{- range $key, $value := . }}
      {{- $configValue := dict }}
      {{- with $value.nodePathMap }}
      {{- $configValue = set $configValue "nodePathMap" . }}
      {{- end }}
      {{- with $value.sharedFileSystemPath }}
      {{- $configValue = set $configValue "sharedFileSystemPath" . }}
      {{- end }}
      {{- $configs = set $configs $key $configValue }}
    {{- end }}
    {{- $config = set $config "storageClassConfigs" $configs }}
    {{- end }}
    {{- $config | toPrettyJson | nindent 4 }}
  setup: |-
    {{- .Values.configmap.setup | nindent 4 }}
  teardown: |-
    {{- .Values.configmap.teardown | nindent 4 }}
  helperPod.yaml: |-
    apiVersion: v1
    kind: Pod
    metadata:
      name: {{ .Values.configmap.helperPod.name }}
      namespace: {{ default (include "local-path-provisioner.namespace" .) .Values.configmap.helperPod.namespaceOverride }}
      {{- with .Values.configmap.helperPod.annotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      priorityClassName: system-node-critical
      tolerations:
        - key: node.kubernetes.io/disk-pressure
          operator: Exists
          effect: NoSchedule
        {{- with .Values.configmap.helperPod.tolerations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      containers:
        - name: helper-pod
          {{- if .Values.privateRegistry.registryUrl }}
          image: {{ .Values.privateRegistry.registryUrl }}/{{ .Values.helperImage.repository }}:{{ .Values.helperImage.tag }}
          {{- else }}
          image: {{ .Values.helperImage.repository }}:{{ .Values.helperImage.tag }}
          {{- end }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources:
            {{- toYaml .Values.helperPod.resources | nindent 12 }}
