From 5e71751a1d35ce94d328251e009887b9864e41f2 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 21 Dec 2015 17:15:34 -0800 Subject: [PATCH] Add node class to constraints --- scheduler/feasible.go | 3 +++ scheduler/feasible_test.go | 13 +++++++++++++ website/source/docs/jobspec/index.html.md | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/scheduler/feasible.go b/scheduler/feasible.go index 9e6782b19..1fb44269d 100644 --- a/scheduler/feasible.go +++ b/scheduler/feasible.go @@ -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] diff --git a/scheduler/feasible_test.go b/scheduler/feasible_test.go index 84ad6d7ee..0f5bce508 100644 --- a/scheduler/feasible_test.go +++ b/scheduler/feasible_test.go @@ -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{ @@ -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) @@ -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, diff --git a/website/source/docs/jobspec/index.html.md b/website/source/docs/jobspec/index.html.md index f55251c2b..cdd8921db 100644 --- a/website/source/docs/jobspec/index.html.md +++ b/website/source/docs/jobspec/index.html.md @@ -339,6 +339,10 @@ Below is a table documenting the variables that can be interpreted: $node.name The client node name + + $node.class + The client node class + $attr.\ The attribute given by `key` on the client node.