Fix macro on local_volume_provisioner (#5168)

mydict.keys() should be converted to list,
otherwise it causes errors in loop iteration.

Remove extra space after class name, which broke configmap.

Also allow set reclaimPolicy property.
This commit is contained in:
andreyshestakov 2019-09-13 10:50:33 +03:00 committed by Kubernetes Prow Robot
parent eb40ac163f
commit cb4f797d32
2 changed files with 7 additions and 5 deletions

View file

@ -1,6 +1,6 @@
# Macro to convert camelCase dictionary keys to snake_case keys # Macro to convert camelCase dictionary keys to snake_case keys
{%- macro convert_keys(mydict) %} {% macro convert_keys(mydict) -%}
{% for key in mydict.keys() -%} {% for key in mydict.keys()|list -%}
{% set key_split = key.split('_') -%} {% set key_split = key.split('_') -%}
{% set new_key = key_split[0] + key_split[1:]|map('capitalize')|join -%} {% set new_key = key_split[0] + key_split[1:]|map('capitalize')|join -%}
{% set value = mydict.pop(key) -%} {% set value = mydict.pop(key) -%}
@ -21,5 +21,4 @@ data:
{{ class_name }}: {{ class_name }}:
{{- convert_keys(storage_class) }} {{- convert_keys(storage_class) }}
{{ storage_class | to_nice_yaml(indent=2) | indent(6) }} {{ storage_class | to_nice_yaml(indent=2) | indent(6) }}
{% endfor %} {%- endfor %}

View file

@ -1,4 +1,4 @@
{% for class_name in local_volume_provisioner_storage_classes.keys() %} {% for class_name, class_config in local_volume_provisioner_storage_classes.items() %}
--- ---
apiVersion: storage.k8s.io/v1 apiVersion: storage.k8s.io/v1
kind: StorageClass kind: StorageClass
@ -6,4 +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 %}
reclaimPolicy: {{ class_config.reclaim_policy }}
{% endif %}
{% endfor %} {% endfor %}