summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-02-12 07:52:19 -0800
committerGitHub <noreply@github.com>2018-02-12 07:52:19 -0800
commit73a0b0eaa3844d4717eb8827c619594bb47acab9 (patch)
treed317653e245fe05b1dec6b07d9f1b12eb74a0bcf /roles/lib_utils
parent81d1735fc7ca16a326cc82b9fe2ce61cf20a1330 (diff)
parent93619d7f090f633ddbd57bb5a41a4d67c83c7c10 (diff)
downloadopenshift-73a0b0eaa3844d4717eb8827c619594bb47acab9.tar.gz
openshift-73a0b0eaa3844d4717eb8827c619594bb47acab9.tar.bz2
openshift-73a0b0eaa3844d4717eb8827c619594bb47acab9.tar.xz
openshift-73a0b0eaa3844d4717eb8827c619594bb47acab9.zip
Merge pull request #7022 from vrutkovs/sanitize-labels
Automatic merge from submit-queue. Verify that requested services have schedulable nodes matching the selectors Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1538445 Not sure if I should keep one task per failure or should group them by service (e.g. all logging check in one tasks)
Diffstat (limited to 'roles/lib_utils')
-rw-r--r--roles/lib_utils/filter_plugins/oo_filters.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/roles/lib_utils/filter_plugins/oo_filters.py b/roles/lib_utils/filter_plugins/oo_filters.py
index c355115b5..ed6bb4c28 100644
--- a/roles/lib_utils/filter_plugins/oo_filters.py
+++ b/roles/lib_utils/filter_plugins/oo_filters.py
@@ -660,6 +660,50 @@ def map_from_pairs(source, delim="="):
return dict(item.split(delim) for item in source.split(","))
+def lib_utils_oo_get_node_labels(source, hostvars=None):
+ ''' Return a list of labels assigned to schedulable nodes '''
+ labels = list()
+
+ # Filter out the unschedulable nodes
+ for host in source:
+ if host not in hostvars:
+ return
+ node_vars = hostvars[host]
+
+ # All nodes are considered schedulable,
+ # unless explicitly marked so
+ schedulable = node_vars.get('openshift_schedulable')
+ if schedulable is None:
+ schedulable = True
+ try:
+ if not strtobool(str(schedulable)):
+ # explicitly marked as unschedulable
+ continue
+ except ValueError:
+ # Incorrect value in openshift_schedulable, skip node
+ continue
+
+ # Get a list of labels from the node
+ node_labels = node_vars.get('openshift_node_labels')
+ if node_labels:
+ labels.append(node_labels)
+
+ return labels
+
+
+def lib_utils_oo_has_no_matching_selector(source, selector=None):
+ ''' Return True when selector cannot be placed
+ on nodes with labels from source '''
+ # Empty selector means any node
+ if not selector:
+ return False
+ for item in source:
+ if selector.items() <= item.items():
+ # Matching selector found
+ return False
+ return True
+
+
class FilterModule(object):
""" Custom ansible filter mapping """
@@ -691,5 +735,7 @@ class FilterModule(object):
"lib_utils_oo_selector_to_string_list": lib_utils_oo_selector_to_string_list,
"lib_utils_oo_filter_sa_secrets": lib_utils_oo_filter_sa_secrets,
"lib_utils_oo_l_of_d_to_csv": lib_utils_oo_l_of_d_to_csv,
- "map_from_pairs": map_from_pairs
+ "lib_utils_oo_has_no_matching_selector": lib_utils_oo_has_no_matching_selector,
+ "lib_utils_oo_get_node_labels": lib_utils_oo_get_node_labels,
+ "map_from_pairs": map_from_pairs,
}