From de2c4429a46bec5e73971ec57f13ad2034425d49 Mon Sep 17 00:00:00 2001
From: Alexander <payback159@gmail.com>
Date: Mon, 22 Jan 2024 18:00:34 +0100
Subject: [PATCH] =?UTF-8?q?Enable=20configuring=20mountOptions,=20reclaimP?=
 =?UTF-8?q?olicy=20and=20volumeBindingMode=20=E2=80=A6=20(#10450)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* Enable configuring mountOptions, reclaimPolicy and volumeBindingMode for cinder-csi StorageClasses

* Check if class.mount_options is defined at all, before generating the option list
---
 inventory/sample/group_vars/all/openstack.yml        | 10 ++++++++++
 .../templates/openstack-storage-class.yml.j2         | 12 ++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/inventory/sample/group_vars/all/openstack.yml b/inventory/sample/group_vars/all/openstack.yml
index 0fec79ad5..cac548f84 100644
--- a/inventory/sample/group_vars/all/openstack.yml
+++ b/inventory/sample/group_vars/all/openstack.yml
@@ -48,3 +48,13 @@
 ## Make sure to source in the openstack credentials
 # cinder_csi_enabled: true
 # cinder_csi_controller_replicas: 1
+# storage_classes:
+#   - name: "cinder-csi"
+#     provisioner: "kubernetes.io/cinder"
+#     mount_options:
+#       - "discard"
+#     parameters:
+#       type: "thin"
+#       availability: "nova"
+#     reclaim_policy: "Delete"
+#     volume_binding_mode: "WaitForFirstConsumer"
diff --git a/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml.j2 b/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml.j2
index 0551e1535..973353c4c 100644
--- a/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml.j2
+++ b/roles/kubernetes-apps/persistent_volumes/openstack/templates/openstack-storage-class.yml.j2
@@ -7,9 +7,21 @@ metadata:
   annotations:
     storageclass.kubernetes.io/is-default-class: "{{ class.is_default | default(false) | ternary("true","false") }}"
 provisioner: kubernetes.io/cinder
+{% if class.mount_options is defined %}
+mountOptions:
+{% for option in class.mount_options | default([]) %}
+  - "{{ option }}"
+{% endfor %}
+{% endif %}
 parameters:
 {% for key, value in (class.parameters | default({})).items() %}
   "{{ key }}": "{{ value }}"
 {% endfor %}
+{% if class.reclaim_policy is defined %}
+reclaimPolicy: "{{ class.reclaim_policy }}"
+{% endif %}
+{% if class.volume_binding_mode is defined %}
+volumeBindingMode: "{{ class.volume_binding_mode }}"
+{% endif %}
 allowVolumeExpansion: {{ expand_persistent_volumes }}
 {% endfor %}
-- 
GitLab