From 90f926957798d96771945fb266af09e8d477b988 Mon Sep 17 00:00:00 2001
From: Andrew Melnick <meln5674@kettering.edu>
Date: Sat, 4 Nov 2023 17:09:40 -0600
Subject: [PATCH] Make multipleStorageClasses a map, not a list, rename to
 match config.json name

---
 README.md                                     |  4 ++-
 .../templates/configmap.yaml                  | 15 +++++++++--
 .../templates/storageclass.yaml               | 10 ++++----
 .../chart/local-path-provisioner/values.yaml  | 25 ++++++++++---------
 4 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/README.md b/README.md
index a3933760..04a580b8 100644
--- a/README.md
+++ b/README.md
@@ -196,9 +196,11 @@ The helperPod is allowed to run on nodes experiencing disk pressure conditions,
 `sharedFileSystemPath` allows the provisioner to use a filesystem that is mounted on all nodes at the same time.
 In this case all access modes are supported: `ReadWriteOnce`, `ReadOnlyMany` and `ReadWriteMany` for storage claims.
 
+`storageClassConfigs` is a map from storage class names to objects containing `nodePathMap` or `sharedFilesystemPath`, as described above.
+
 In addition `volumeBindingMode: Immediate` can be used in  StorageClass definition.
 
-Please note that `nodePathMap` and `sharedFileSystemPath` are mutually exclusive. If `sharedFileSystemPath` is used, then `nodePathMap` must be set to `[]`.
+Please note that `nodePathMap`, `sharedFileSystemPath`, and `storageClassConfigs` are mutually exclusive. If `sharedFileSystemPath` or `stroageClassConfigs` are used, then `nodePathMap` must be set to `[]`.
 
 The `setupCommand` and `teardownCommand` allow you to specify the path to binary files in helperPod that will be called when creating or deleting pvc respectively. This can be useful if you need to use distroless images for security reasons. See the examples/distroless directory for an example. A binary file can take the following parameters:
 | Parameter | Description |
diff --git a/deploy/chart/local-path-provisioner/templates/configmap.yaml b/deploy/chart/local-path-provisioner/templates/configmap.yaml
index 0f45cdab..60181e06 100644
--- a/deploy/chart/local-path-provisioner/templates/configmap.yaml
+++ b/deploy/chart/local-path-provisioner/templates/configmap.yaml
@@ -14,8 +14,19 @@ data:
     {{- with .Values.sharedFileSystemPath }}
     {{- $config = set $config "sharedFileSystemPath" . }}
     {{- end }}
-    {{- with .Values.multipleStorageClasses }}
-    {{- $config = set $config "sharedFileSystemPath" . }}
+    {{- 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: |-
diff --git a/deploy/chart/local-path-provisioner/templates/storageclass.yaml b/deploy/chart/local-path-provisioner/templates/storageclass.yaml
index 70fe8c99..6a41ce15 100644
--- a/deploy/chart/local-path-provisioner/templates/storageclass.yaml
+++ b/deploy/chart/local-path-provisioner/templates/storageclass.yaml
@@ -1,16 +1,16 @@
 {{- $storageClasses := list }}
-{{ if .Values.multipleStorageClasses }}
-{{ $storageClasses = .Values.multipleStorageClasses }}
+{{ if .Values.storageClassConfigs }}
+{{ $storageClasses = .Values.storageClassConfigs }}
 {{- else }}
-{{ $storageClasses = list .Values }}
+{{ $storageClasses = dict .Values.storageClass.name .Values }}
 {{ end }}
 {{- $dot := . }}
-{{- range $values := $storageClasses }}
+{{- range $name, $values := $storageClasses }}
 {{ if $values.storageClass.create -}}
 apiVersion: storage.k8s.io/v1
 kind: StorageClass
 metadata:
-  name: {{ $values.storageClass.name }}
+  name: {{ $name }}
   labels:
 {{ include "local-path-provisioner.labels" $dot | indent 4 }}
   annotations:
diff --git a/deploy/chart/local-path-provisioner/values.yaml b/deploy/chart/local-path-provisioner/values.yaml
index 5b3fb0b7..b3a6c549 100644
--- a/deploy/chart/local-path-provisioner/values.yaml
+++ b/deploy/chart/local-path-provisioner/values.yaml
@@ -73,20 +73,21 @@ nodePathMap:
 # If `sharedFileSystemPath` is used, then `nodePathMap` must be set to `[]`.
 # sharedFileSystemPath: ""
 
-# `multipleStorageClasses` allows the provisioner to manage multiple independent storage classes.
+# `storageClassConfigs` allows the provisioner to manage multiple independent storage classes.
 # Each storage class must have a unique name, and contains the same fields as shown above for
 # a single storage class setup, EXCEPT for the provisionerName, which is the same for all
-# storage classes
-# multipleStorageClasses:
-# - storageClass:
-#     name: my-storage-class-name
-#     create: true
-#     defaultClass: false
-#     reclaimPolicy: Delete
-#   sharedFileSystemPath: ""
-#   ## OR
-#   # See above
-#   nodePathMap: {}
+# storage classes, and name, which is the key of the map.
+# storageClassConfigs: {}
+#   my-storage-class:
+#     storageClass:
+#       create: true
+#       defaultClass: false
+#       defaultVolumeType: hostPath
+#       reclaimPolicy: Delete
+#     sharedFileSystemPath: ""
+#     ## OR
+#     # See above
+#     nodePathMap: {}
     
 podAnnotations: {}
 
-- 
GitLab