Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node class to constraints #618

Merged
merged 1 commit into from
Dec 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ func resolveConstraintTarget(target string, node *structs.Node) (interface{}, bo
case "$node.name" == target:
return node.Name, true

case "$node.class" == target:
return node.NodeClass, true

case strings.HasPrefix(target, "$attr."):
attr := strings.TrimPrefix(target, "$attr.")
val, ok := node.Attributes[attr]
Expand Down
13 changes: 13 additions & 0 deletions scheduler/feasible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ func TestConstraintIterator(t *testing.T) {
mock.Node(),
mock.Node(),
mock.Node(),
mock.Node(),
}
static := NewStaticIterator(ctx, nodes)

nodes[0].Attributes["kernel.name"] = "freebsd"
nodes[1].Datacenter = "dc2"
nodes[2].NodeClass = "large"

constraints := []*structs.Constraint{
&structs.Constraint{
Expand All @@ -129,6 +131,11 @@ func TestConstraintIterator(t *testing.T) {
LTarget: "$attr.kernel.name",
RTarget: "linux",
},
&structs.Constraint{
Operand: "is",
LTarget: "$node.class",
RTarget: "large",
},
}
constr := NewConstraintIterator(ctx, static, constraints)

Expand Down Expand Up @@ -168,6 +175,12 @@ func TestResolveConstraintTarget(t *testing.T) {
val: node.Name,
result: true,
},
{
target: "$node.class",
node: node,
val: node.NodeClass,
result: true,
},
{
target: "$node.foo",
node: node,
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/jobspec/index.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ Below is a table documenting the variables that can be interpreted:
<td>$node.name</td>
<td>The client node name</td>
</tr>
<tr>
<td>$node.class</td>
<td>The client node class</td>
</tr>
<tr>
<td>$attr.\<key\></td>
<td>The attribute given by `key` on the client node.</td>
Expand Down