Merge pull request #618 from hashicorp/f-node-class-constraint

Add node class to constraints
This commit is contained in:
Alex Dadgar 2015-12-28 13:27:38 -08:00
commit d6aa36b417
3 changed files with 20 additions and 0 deletions

View File

@ -335,6 +335,9 @@ func resolveConstraintTarget(target string, node *structs.Node) (interface{}, bo
case "$node.name" == target: case "$node.name" == target:
return node.Name, true return node.Name, true
case "$node.class" == target:
return node.NodeClass, true
case strings.HasPrefix(target, "$attr."): case strings.HasPrefix(target, "$attr."):
attr := strings.TrimPrefix(target, "$attr.") attr := strings.TrimPrefix(target, "$attr.")
val, ok := node.Attributes[attr] val, ok := node.Attributes[attr]

View File

@ -112,11 +112,13 @@ func TestConstraintIterator(t *testing.T) {
mock.Node(), mock.Node(),
mock.Node(), mock.Node(),
mock.Node(), mock.Node(),
mock.Node(),
} }
static := NewStaticIterator(ctx, nodes) static := NewStaticIterator(ctx, nodes)
nodes[0].Attributes["kernel.name"] = "freebsd" nodes[0].Attributes["kernel.name"] = "freebsd"
nodes[1].Datacenter = "dc2" nodes[1].Datacenter = "dc2"
nodes[2].NodeClass = "large"
constraints := []*structs.Constraint{ constraints := []*structs.Constraint{
&structs.Constraint{ &structs.Constraint{
@ -129,6 +131,11 @@ func TestConstraintIterator(t *testing.T) {
LTarget: "$attr.kernel.name", LTarget: "$attr.kernel.name",
RTarget: "linux", RTarget: "linux",
}, },
&structs.Constraint{
Operand: "is",
LTarget: "$node.class",
RTarget: "large",
},
} }
constr := NewConstraintIterator(ctx, static, constraints) constr := NewConstraintIterator(ctx, static, constraints)
@ -168,6 +175,12 @@ func TestResolveConstraintTarget(t *testing.T) {
val: node.Name, val: node.Name,
result: true, result: true,
}, },
{
target: "$node.class",
node: node,
val: node.NodeClass,
result: true,
},
{ {
target: "$node.foo", target: "$node.foo",
node: node, node: node,

View File

@ -357,6 +357,10 @@ Below is a table documenting the variables that can be interpreted:
<td>$node.name</td> <td>$node.name</td>
<td>The client node name</td> <td>The client node name</td>
</tr> </tr>
<tr>
<td>$node.class</td>
<td>The client node class</td>
</tr>
<tr> <tr>
<td>$attr.\<key\></td> <td>$attr.\<key\></td>
<td>The attribute given by `key` on the client node.</td> <td>The attribute given by `key` on the client node.</td>