Skip to content

Commit

Permalink
Merge pull request #5 from shivramsrivastava/dev
Browse files Browse the repository at this point in the history
Support for GT an LT operators for node affinity.
  • Loading branch information
shivramsrivastava authored Jun 15, 2018
2 parents 7c616c5 + c45c413 commit f7f252b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/base/label_selector.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 18 additions & 0 deletions src/scheduling/label_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ RepeatedPtrField<LabelSelector> 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<LabelSelector_SelectorType>(type));
for (auto& value : nsm.values()) {
selector.add_values(value);
Expand Down Expand Up @@ -177,6 +181,20 @@ bool SatisfiesLabelSelector(const unordered_map<string, string>& 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();
}
Expand Down

0 comments on commit f7f252b

Please sign in to comment.