local_volume_provisioner: match upstream storage class syntax (#13504)

Use the upstream keys without converting them to snake case. This avoids
converting back to camel case when rendering, and aligns ourselves more
with our upstream.
This commit is contained in:
Max Gautier
2026-09-14 15:45:22 +00:00
committed by GitHub
parent 49ca08fe0d
commit b1b01bc579
7 changed files with 28 additions and 46 deletions
@@ -3,7 +3,7 @@
The [local static storage provisioner](https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner) The [local static storage provisioner](https://github.com/kubernetes-sigs/sig-storage-local-static-provisioner)
is NOT a dynamic storage provisioner as you would is NOT a dynamic storage provisioner as you would
expect from a cloud provider. Instead, it simply creates PersistentVolumes for expect from a cloud provider. Instead, it simply creates PersistentVolumes for
all mounts under the `host_dir` of the specified storage class. all mounts under the `hostDir` of the specified storage class.
These storage classes are specified in the `local_volume_provisioner_storage_classes` nested dictionary. These storage classes are specified in the `local_volume_provisioner_storage_classes` nested dictionary.
Example: Example:
@@ -11,24 +11,18 @@ Example:
```yaml ```yaml
local_volume_provisioner_storage_classes: local_volume_provisioner_storage_classes:
local-storage: local-storage:
host_dir: /mnt/disks hostDir: /mnt/disks
mount_dir: /mnt/disks mountDir: /mnt/disks
fast-disks: fast-disks:
host_dir: /mnt/fast-disks hostDir: /mnt/fast-disks
mount_dir: /mnt/fast-disks mountDir: /mnt/fast-disks
block_cleaner_command: blockCleanerCommand:
- "/scripts/shred.sh" - "/scripts/shred.sh"
- "2" - "2"
volume_mode: Filesystem volumeMode: Filesystem
fs_type: ext4 fsType: ext4
``` ```
For each key in `local_volume_provisioner_storage_classes` a "storage class" with
the same name is created in the entry `storageClassMap` of the ConfigMap `local-volume-provisioner`.
The subkeys of each storage class in `local_volume_provisioner_storage_classes`
are converted to camelCase and added as attributes to the storage class in the
ConfigMap.
The result of the above example is: The result of the above example is:
```yaml ```yaml
@@ -93,14 +87,14 @@ the rest of this documentation will use that path as an example.
``` ```
This saves time of precreating filesystems. Note that your storageclass must have This saves time of precreating filesystems. Note that your storageclass must have
`volume_mode` set to `"Filesystem"` and `fs_type` defined. If either is not set, the `volumeMode` set to `"Filesystem"` and `fsType` defined. If either is not set, the
disk will be added as a raw block device. disk will be added as a raw block device.
1. PersistentVolumes with `volumeMode="Block"` 1. PersistentVolumes with `volumeMode="Block"`
Just like above, you can create PersistentVolumes with volumeMode `Block` Just like above, you can create PersistentVolumes with volumeMode `Block`
by creating a symbolic link under discovery directory to the block device on by creating a symbolic link under discovery directory to the block device on
the node, if you set `volume_mode` to `"Block"`. This will create a volume the node, if you set `volumeMode` to `"Block"`. This will create a volume
presented into a Pod as a block device, without any filesystem on it. presented into a Pod as a block device, without any filesystem on it.
1. File-backed sparsefile method 1. File-backed sparsefile method
@@ -37,18 +37,18 @@ local_volume_provisioner_enabled: false
# - topology.kubernetes.io/zone # - topology.kubernetes.io/zone
# local_volume_provisioner_storage_classes: # local_volume_provisioner_storage_classes:
# local-storage: # local-storage:
# host_dir: /mnt/disks # hostDir: /mnt/disks
# mount_dir: /mnt/disks # mountDir: /mnt/disks
# volume_mode: Filesystem # volumeMode: Filesystem
# fs_type: ext4 # fsType: ext4
# fast-disks: # fast-disks:
# host_dir: /mnt/fast-disks # hostDir: /mnt/fast-disks
# mount_dir: /mnt/fast-disks # mountDir: /mnt/fast-disks
# block_cleaner_command: # blockCleanerCommand:
# - "/scripts/shred.sh" # - "/scripts/shred.sh"
# - "2" # - "2"
# volume_mode: Filesystem # volumeMode: Filesystem
# fs_type: ext4 # fsType: ext4
# local_volume_provisioner_tolerations: # local_volume_provisioner_tolerations:
# - effect: NoSchedule # - effect: NoSchedule
# operator: Exists # operator: Exists
@@ -1,14 +1,3 @@
# Macro to convert camelCase dictionary keys to snake_case keys
{% macro convert_keys(mydict) -%}
{% for key in mydict.keys() | list -%}
{% set key_split = key.split('_') -%}
{% set new_key = key_split[0] + key_split[1:] | map('capitalize') | join -%}
{% set value = mydict.pop(key) -%}
{{ mydict.__setitem__(new_key, value) -}}
{{ convert_keys(value) if value is mapping else None -}}
{% endfor -%}
{% endmacro -%}
--- ---
apiVersion: v1 apiVersion: v1
kind: ConfigMap kind: ConfigMap
@@ -28,6 +17,5 @@ data:
storageClassMap: | storageClassMap: |
{% for class_name, storage_class in local_volume_provisioner_storage_classes.items() %} {% for class_name, storage_class in local_volume_provisioner_storage_classes.items() %}
{{ class_name }}: {{ class_name }}:
{{- convert_keys(storage_class) }}
{{ storage_class | to_nice_yaml(indent=2) | indent(6) }} {{ storage_class | to_nice_yaml(indent=2) | indent(6) }}
{%- endfor %} {%- endfor %}
@@ -51,7 +51,7 @@ spec:
name: provisioner-dev name: provisioner-dev
{% for class_name, class_config in local_volume_provisioner_storage_classes.items() %} {% for class_name, class_config in local_volume_provisioner_storage_classes.items() %}
- name: local-volume-provisioner-hostpath-{{ class_name }} - name: local-volume-provisioner-hostpath-{{ class_name }}
mountPath: {{ class_config.mount_dir }} mountPath: {{ class_config.mountDir }}
mountPropagation: "HostToContainer" mountPropagation: "HostToContainer"
{% endfor %} {% endfor %}
volumes: volumes:
@@ -64,5 +64,5 @@ spec:
{% for class_name, class_config in local_volume_provisioner_storage_classes.items() %} {% for class_name, class_config in local_volume_provisioner_storage_classes.items() %}
- name: local-volume-provisioner-hostpath-{{ class_name }} - name: local-volume-provisioner-hostpath-{{ class_name }}
hostPath: hostPath:
path: {{ class_config.host_dir }} path: {{ class_config.hostDir }}
{% endfor %} {% endfor %}
@@ -6,7 +6,7 @@ metadata:
name: {{ class_name }} name: {{ class_name }}
provisioner: kubernetes.io/no-provisioner provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer volumeBindingMode: WaitForFirstConsumer
{% if class_config.reclaim_policy is defined %} {% if class_config.reclaimPolicy is defined %}
reclaimPolicy: {{ class_config.reclaim_policy }} reclaimPolicy: {{ class_config.reclaimPolicy }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@@ -103,7 +103,7 @@
- name: Create local volume provisioner directories - name: Create local volume provisioner directories
file: file:
path: "{{ local_volume_provisioner_storage_classes[item].host_dir }}" path: "{{ local_volume_provisioner_storage_classes[item].hostDir }}"
state: directory state: directory
owner: root owner: root
group: root group: root
+4 -4
View File
@@ -69,10 +69,10 @@ kube_pods_subnets: >-
local_volume_provisioner_storage_classes_default: local_volume_provisioner_storage_classes_default:
- key: "{{ local_volume_provisioner_storage_class }}" - key: "{{ local_volume_provisioner_storage_class }}"
value: value:
host_dir: "{{ local_volume_provisioner_base_dir }}" hostDir: "{{ local_volume_provisioner_base_dir }}"
mount_dir: "{{ local_volume_provisioner_mount_dir }}" mountDir: "{{ local_volume_provisioner_mount_dir }}"
volume_mode: Filesystem volumeMode: Filesystem
fs_type: ext4 fsType: ext4
ssl_ca_dirs_per_os_family: ssl_ca_dirs_per_os_family:
Debian: &usr_share Debian: &usr_share