From b497f7a2a77c3ef1434a5f0bd11fccf9d81b44aa Mon Sep 17 00:00:00 2001 From: Diego Castro Date: Tue, 4 Aug 2015 11:10:35 -0300 Subject: Fix node labeling. Issue #305 --- filter_plugins/oo_filters.py | 11 +++++++++++ playbooks/common/openshift-node/config.yml | 5 ++++- roles/openshift_manage_node/tasks/main.yml | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py index 47033a88e..9c263f0dd 100644 --- a/filter_plugins/oo_filters.py +++ b/filter_plugins/oo_filters.py @@ -130,6 +130,16 @@ class FilterModule(object): rval.append("%s%s%s" % (item['key'], joiner, item['value'])) return rval + + @staticmethod + def oo_combine_dict(data, in_joiner='=', out_joiner=' '): + '''Take a dict in the form of { 'key': 'value', 'key': 'value' } and + arrange them as a string 'key=value key=value' + ''' + if not issubclass(type(data), dict): + raise errors.AnsibleFilterError("|failed expects first param is a dict") + + return out_joiner.join([ in_joiner.join([k, v]) for k, v in data.items() ]) @staticmethod def oo_ami_selector(data, image_name): @@ -309,6 +319,7 @@ class FilterModule(object): "oo_ami_selector": self.oo_ami_selector, "oo_ec2_volume_definition": self.oo_ec2_volume_definition, "oo_combine_key_value": self.oo_combine_key_value, + "oo_combine_dict": self.oo_combine_dict, "oo_split": self.oo_split, "oo_filter_list": self.oo_filter_list, "oo_parse_heat_stack_outputs": self.oo_parse_heat_stack_outputs diff --git a/playbooks/common/openshift-node/config.yml b/playbooks/common/openshift-node/config.yml index 6ef375bbb..122cfbf92 100644 --- a/playbooks/common/openshift-node/config.yml +++ b/playbooks/common/openshift-node/config.yml @@ -126,9 +126,12 @@ - name: Set scheduleability hosts: oo_first_master vars: + openshift_node_labels: "{{ hostvars + | oo_select_keys(groups['oo_nodes_to_config']) + | oo_collect('openshift.node.labels') }}" openshift_nodes: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) - | oo_collect('openshift.common.hostname') }}" + | oo_collect('openshift.common.hostname') }}" openshift_unscheduleable_nodes: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config'] | default([])) | oo_collect('openshift.common.hostname', {'openshift_scheduleable': False}) }}" pre_tasks: diff --git a/roles/openshift_manage_node/tasks/main.yml b/roles/openshift_manage_node/tasks/main.yml index d17f3f532..e64d6e713 100644 --- a/roles/openshift_manage_node/tasks/main.yml +++ b/roles/openshift_manage_node/tasks/main.yml @@ -16,3 +16,10 @@ command: > {{ openshift.common.admin_binary }} manage-node {{ item }} --schedulable=true with_items: openshift_scheduleable_nodes + +- name: Tag schedulable nodes + command: > + {{ openshift.common.client_binary }} label --overwrite node {{ item.0 }} {{ item.1 | oo_combine_dict }} + with_nested: + - openshift_scheduleable_nodes + - openshift_node_labels \ No newline at end of file -- cgit v1.2.3 From 6be237602331e88a330c1f46d31aeb97d9af1aa2 Mon Sep 17 00:00:00 2001 From: "Diego Castro (dscastro)" Date: Tue, 4 Aug 2015 11:53:07 -0300 Subject: Applying changes suggested by @sdodson --- roles/openshift_manage_node/tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roles/openshift_manage_node/tasks/main.yml b/roles/openshift_manage_node/tasks/main.yml index e64d6e713..257bcee2c 100644 --- a/roles/openshift_manage_node/tasks/main.yml +++ b/roles/openshift_manage_node/tasks/main.yml @@ -17,9 +17,9 @@ {{ openshift.common.admin_binary }} manage-node {{ item }} --schedulable=true with_items: openshift_scheduleable_nodes -- name: Tag schedulable nodes +- name: Label nodes command: > {{ openshift.common.client_binary }} label --overwrite node {{ item.0 }} {{ item.1 | oo_combine_dict }} with_nested: - - openshift_scheduleable_nodes - - openshift_node_labels \ No newline at end of file + - openshift_nodes + - openshift_node_labels -- cgit v1.2.3 From c17efa0172a11f79cb28d3c5740b7c16ed70c3b8 Mon Sep 17 00:00:00 2001 From: Diego Castro Date: Sun, 9 Aug 2015 12:40:28 -0300 Subject: Fix node labels --- playbooks/common/openshift-node/config.yml | 3 --- roles/openshift_manage_node/tasks/main.yml | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/playbooks/common/openshift-node/config.yml b/playbooks/common/openshift-node/config.yml index 122cfbf92..4010b4c9e 100644 --- a/playbooks/common/openshift-node/config.yml +++ b/playbooks/common/openshift-node/config.yml @@ -126,9 +126,6 @@ - name: Set scheduleability hosts: oo_first_master vars: - openshift_node_labels: "{{ hostvars - | oo_select_keys(groups['oo_nodes_to_config']) - | oo_collect('openshift.node.labels') }}" openshift_nodes: "{{ hostvars | oo_select_keys(groups['oo_nodes_to_config']) | oo_collect('openshift.common.hostname') }}" diff --git a/roles/openshift_manage_node/tasks/main.yml b/roles/openshift_manage_node/tasks/main.yml index 257bcee2c..c488af723 100644 --- a/roles/openshift_manage_node/tasks/main.yml +++ b/roles/openshift_manage_node/tasks/main.yml @@ -19,7 +19,6 @@ - name: Label nodes command: > - {{ openshift.common.client_binary }} label --overwrite node {{ item.0 }} {{ item.1 | oo_combine_dict }} - with_nested: - - openshift_nodes - - openshift_node_labels + {{ openshift.common.client_binary }} label --overwrite node {{ item }} {{ hostvars[item]['openshift_node_labels'] | oo_combine_dict }} + with_items: + - "{{ openshift_nodes }}" -- cgit v1.2.3 From 9a41d23f553ab638af22f54fbd30c4de3b0eae18 Mon Sep 17 00:00:00 2001 From: Diego Castro Date: Mon, 10 Aug 2015 11:50:57 -0300 Subject: Don't try to label node if there's no labels --- roles/openshift_manage_node/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/openshift_manage_node/tasks/main.yml b/roles/openshift_manage_node/tasks/main.yml index c488af723..472d63efe 100644 --- a/roles/openshift_manage_node/tasks/main.yml +++ b/roles/openshift_manage_node/tasks/main.yml @@ -22,3 +22,5 @@ {{ openshift.common.client_binary }} label --overwrite node {{ item }} {{ hostvars[item]['openshift_node_labels'] | oo_combine_dict }} with_items: - "{{ openshift_nodes }}" + when: + "'openshift_node_labels' in hostvars[item]" -- cgit v1.2.3 From 7a12b210856a2abefb2a7d70448975c7f2ce14af Mon Sep 17 00:00:00 2001 From: "Diego Castro (dscastro)" Date: Wed, 12 Aug 2015 11:44:34 -0300 Subject: Notes for schedule behavior. --- roles/openshift_node/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/roles/openshift_node/README.md b/roles/openshift_node/README.md index 5edb3b8dd..300e6b495 100644 --- a/roles/openshift_node/README.md +++ b/roles/openshift_node/README.md @@ -34,6 +34,18 @@ openshift_common Example Playbook ---------------- +Notes +----- + +Currently we support re-labeling nodes but we don't re-schedule running pods nor remove existing labels. That means you will have to trigger the re-schedulling manually. To re-schedule your pods, just follow the steps below: + +``` +oadm manage-node --schedulable=false ${NODE} +oadm manage-node --evacuate ${NODE} +oadm manage-node --schedulable=true ${NODE} +```` + + TODO License -- cgit v1.2.3