From a870dd368e5e02d490ab40468113d41b3f342a92 Mon Sep 17 00:00:00 2001 From: Lukas Grossar Date: Thu, 17 Sep 2020 11:44:58 +0200 Subject: [PATCH] Allow configuration of nodelabels in local_volume_provisioner (#6620) --- inventory/sample/group_vars/k8s-cluster/addons.yml | 4 ++++ .../local_volume_provisioner/defaults/main.yml | 5 +++++ .../templates/local-volume-provisioner-cm.yml.j2 | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/inventory/sample/group_vars/k8s-cluster/addons.yml b/inventory/sample/group_vars/k8s-cluster/addons.yml index e085ac897..c03ac1c29 100644 --- a/inventory/sample/group_vars/k8s-cluster/addons.yml +++ b/inventory/sample/group_vars/k8s-cluster/addons.yml @@ -33,6 +33,10 @@ local_path_provisioner_enabled: false # Local volume provisioner deployment local_volume_provisioner_enabled: false # local_volume_provisioner_namespace: kube-system +# local_volume_provisioner_nodelabels: +# - kubernetes.io/hostname +# - topology.kubernetes.io/region +# - topology.kubernetes.io/zone # local_volume_provisioner_storage_classes: # local-storage: # host_dir: /mnt/disks diff --git a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/defaults/main.yml b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/defaults/main.yml index c9a2b5c75..fc4a958c1 100644 --- a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/defaults/main.yml +++ b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/defaults/main.yml @@ -1,5 +1,10 @@ --- local_volume_provisioner_namespace: "kube-system" +# List of node labels to be copied to the PVs created by the provisioner +local_volume_provisioner_nodelabels: [] +# - kubernetes.io/hostname +# - topology.kubernetes.io/region +# - topology.kubernetes.io/zone # Levarages Ansibles string to Python datatype casting. Otherwise the dict_key isn't substituted # see https://github.com/ansible/ansible/issues/17324 local_volume_provisioner_storage_classes: | diff --git a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/templates/local-volume-provisioner-cm.yml.j2 b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/templates/local-volume-provisioner-cm.yml.j2 index 3aa90fccd..21807fe43 100644 --- a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/templates/local-volume-provisioner-cm.yml.j2 +++ b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/templates/local-volume-provisioner-cm.yml.j2 @@ -16,6 +16,12 @@ metadata: name: local-volume-provisioner namespace: {{ local_volume_provisioner_namespace }} data: +{% if local_volume_provisioner_nodelabels | length > 0 %} + nodeLabelsForPV: | +{% for nodelabel in local_volume_provisioner_nodelabels %} + - {{ nodelabel }} +{% endfor %} +{% endif %} storageClassMap: | {% for class_name, storage_class in local_volume_provisioner_storage_classes.items() %} {{ class_name }}: