From 8485136f9afbb1c19bab64453011b48853be828f Mon Sep 17 00:00:00 2001 From: Mateus Caruccio Date: Sun, 19 May 2019 16:31:10 -0300 Subject: [PATCH] var node_labels as string (#4764) --- docs/vars.md | 4 +++- roles/kubernetes/node/templates/kubelet.env.j2 | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/vars.md b/docs/vars.md index 55cdae590..b01dafd18 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -117,11 +117,13 @@ Stack](https://github.com/kubernetes-sigs/kubespray/blob/master/docs/dns-stack.m from the kube-apiserver when the certificate expiration approaches. * *node_labels* - Labels applied to nodes via kubelet --node-labels parameter. For example, labels can be set in the inventory as variables or more widely in group_vars. - *node_labels* must be defined as a dict: + *node_labels* can be defined either as a dict or a comma-separaded labels string: ``` node_labels: label1_name: label1_value label2_name: label2_value + +node_labels: "label1_name=label1_value,label2_name=label2_value" ``` * *node_taints* - Taints applied to nodes via kubelet --register-with-taints parameter. For example, taints can be set in the inventory as variables or more widely in group_vars. diff --git a/roles/kubernetes/node/templates/kubelet.env.j2 b/roles/kubernetes/node/templates/kubelet.env.j2 index 98cf409ee..a5fd64b1a 100644 --- a/roles/kubernetes/node/templates/kubelet.env.j2 +++ b/roles/kubernetes/node/templates/kubelet.env.j2 @@ -91,11 +91,16 @@ KUBELET_HOSTNAME="--hostname-override={{ kube_override_hostname }}" {% endif %} {% set inventory_node_labels = [] %} -{% if node_labels is defined and node_labels is mapping %} -{% for labelname, labelvalue in node_labels.items() %} -{% set dummy = inventory_node_labels.append('%s=%s'|format(labelname, labelvalue)) %} -{% endfor %} -{% endif %} +{% if node_labels is defined %} +{% if node_labels is mapping %} +{% for labelname, labelvalue in node_labels.items() %} +{% set dummy = inventory_node_labels.append('%s=%s'|format(labelname, labelvalue)) %} +{% endfor %} +{% else %} +{% for label in node_labels.split(",") %} +{% set dummy = inventory_node_labels.append(label) %} +{% endfor %} +{% endif %} {% set all_node_labels = role_node_labels + inventory_node_labels %} {# Kubelet node taints for gpu #}