From c45c4136f4342282636f0b589e87754289bdac28 Mon Sep 17 00:00:00 2001 From: shivramsrivastava Date: Fri, 15 Jun 2018 05:29:40 +0000 Subject: [PATCH] Support for GT an LT operators for node affinity. --- src/base/label_selector.proto | 4 +++- src/scheduling/label_utils.cc | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/base/label_selector.proto b/src/base/label_selector.proto index 0a8686013..ffb40dfab 100644 --- a/src/base/label_selector.proto +++ b/src/base/label_selector.proto @@ -12,9 +12,11 @@ message LabelSelector { NOT_IN_SET = 1; EXISTS_KEY = 2; NOT_EXISTS_KEY = 3; + GREATER_THAN = 4; + LESSER_THAN = 5; } SelectorType type = 1; string key = 2; repeated string values = 3; -} \ No newline at end of file +} diff --git a/src/scheduling/label_utils.cc b/src/scheduling/label_utils.cc index 50dcb1768..eeb270066 100644 --- a/src/scheduling/label_utils.cc +++ b/src/scheduling/label_utils.cc @@ -42,6 +42,10 @@ RepeatedPtrField NodeSelectorRequirementsAsLabelSelectors( type = 2; else if (operator_type == "DoesNotExist") type = 3; + else if (operator_type == "Gt") + type = 4; + else if (operator_type == "Lt") + type = 5; selector.set_type(static_cast(type)); for (auto& value : nsm.values()) { selector.add_values(value); @@ -177,6 +181,20 @@ bool SatisfiesLabelSelector(const unordered_map& rd_labels, case LabelSelector::NOT_EXISTS_KEY: { return !ContainsKey(rd_labels, selector.key()); } + case LabelSelector::GREATER_THAN: { + const string* value = FindOrNull(rd_labels, selector.key()); + if (value != NULL) { + return (stoi(*value) > stoi(*selector_values.begin())); + } + return false; + } + case LabelSelector::LESSER_THAN: { + const string* value = FindOrNull(rd_labels, selector.key()); + if (value != NULL) { + return (stoi(*value) < stoi(*selector_values.begin())); + } + return false; + } default: LOG(FATAL) << "Unsupported selector type: " << selector.type(); }