From a9c4d188ed1b2662ba4845c8c146aa2f20ad4100 Mon Sep 17 00:00:00 2001
From: Alban Bedel <alban.bedel@aerq.com>
Date: Wed, 24 Jan 2024 12:42:01 +0100
Subject: [PATCH] deployment: Add support for the storage class path pattern to
 the chart

Add the `pathPattern` parameter to the storage class values so it can
also be configured from the helm chart.

Signed-off-by: Alban Bedel <alban.bedel@aerq.com>
---
 deploy/chart/local-path-provisioner/README.md                 | 1 +
 .../chart/local-path-provisioner/templates/storageclass.yaml  | 4 ++++
 deploy/chart/local-path-provisioner/values.yaml               | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/deploy/chart/local-path-provisioner/README.md b/deploy/chart/local-path-provisioner/README.md
index b791bd74..e6fe9670 100644
--- a/deploy/chart/local-path-provisioner/README.md
+++ b/deploy/chart/local-path-provisioner/README.md
@@ -64,6 +64,7 @@ default values.
 | `storageClass.defaultVolumeType`    | The default volume type this storage class creates                              | `hostPath`                                                                          |
 | `storageClass.name`                 | The name to assign the created StorageClass                                     | local-path                                                                          |
 | `storageClass.reclaimPolicy`        | ReclaimPolicy field of the class                                                | Delete                                                                              |
+| `storageClass.pathPattern`          | Template for the volume directory name                                          | `nil`                                                                               |
 | `nodePathMap`                       | Configuration of where to store the data on each node                           | `[{node: DEFAULT_PATH_FOR_NON_LISTED_NODES, paths: [/opt/local-path-provisioner]}]` |
 | `resources`                         | Local Path Provisioner resource requests & limits                               | `{}`                                                                                |
 | `rbac.create`                       | If true, create & use RBAC resources                                            | `true`                                                                              |
diff --git a/deploy/chart/local-path-provisioner/templates/storageclass.yaml b/deploy/chart/local-path-provisioner/templates/storageclass.yaml
index 6a41ce15..0bddf7b0 100644
--- a/deploy/chart/local-path-provisioner/templates/storageclass.yaml
+++ b/deploy/chart/local-path-provisioner/templates/storageclass.yaml
@@ -20,6 +20,10 @@ provisioner: {{ template "local-path-provisioner.provisionerName" $dot }}
 volumeBindingMode: {{ $values.storageClass.volumeBindingMode }}
 reclaimPolicy: {{ $values.storageClass.reclaimPolicy }}
 allowVolumeExpansion: true
+{{- if .Values.storageClass.pathPattern }}
+parameters:
+  pathPattern: {{ .Values.storageClass.pathPattern | quote }}
+{{  end -}}
 {{- end }}
 ---
 {{- end }}
diff --git a/deploy/chart/local-path-provisioner/values.yaml b/deploy/chart/local-path-provisioner/values.yaml
index d682a556..1e055fe2 100644
--- a/deploy/chart/local-path-provisioner/values.yaml
+++ b/deploy/chart/local-path-provisioner/values.yaml
@@ -47,6 +47,9 @@ storageClass:
   ## volumeBindingMode field controls when volume binding and dynamic provisioning should occur, can be  "Immediate" or "WaitForFirstConsumer"
   volumeBindingMode: WaitForFirstConsumer
 
+  ## Set a path pattern, if unset the default will be used
+  # pathPattern: "{{ .PVC.Namespace }}-{{ .PVC.Name }}"
+
 # nodePathMap is the place user can customize where to store the data on each node.
 # 1. If one node is not listed on the nodePathMap, and Kubernetes wants to create volume on it, the paths specified in
 #    DEFAULT_PATH_FOR_NON_LISTED_NODES will be used for provisioning.
-- 
GitLab