Documentation and making unique first class in the constraint block

This commit is contained in:
Alex Dadgar 2015-10-22 16:37:20 -07:00
parent 783b0b5aee
commit 602baa37ce
3 changed files with 41 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv"
"strings" "strings"
"time" "time"
@ -256,6 +257,20 @@ func parseConstraints(result *[]*structs.Constraint, obj *hclobj.Object) error {
m["RTarget"] = constraint m["RTarget"] = constraint
} }
if value, ok := m["unique"]; ok {
enabled, err := strconv.ParseBool(value.(string))
if err != nil {
return err
}
// If it is not enabled, skip the constraint.
if !enabled {
continue
}
m["Operand"] = "unique"
}
// Build the constraint // Build the constraint
var c structs.Constraint var c structs.Constraint
if err := mapstructure.WeakDecode(m, &c); err != nil { if err := mapstructure.WeakDecode(m, &c); err != nil {

View File

@ -192,6 +192,24 @@ func TestParse(t *testing.T) {
false, false,
}, },
{
"unique-constraint.hcl",
&structs.Job{
ID: "foo",
Name: "foo",
Priority: 50,
Region: "global",
Type: "service",
Constraints: []*structs.Constraint{
&structs.Constraint{
Hard: true,
Operand: "unique",
},
},
},
false,
},
{ {
"specify-job.hcl", "specify-job.hcl",
&structs.Job{ &structs.Job{

View File

@ -237,6 +237,14 @@ The `constraint` object supports the following keys:
the attribute. This sets the operator to "regexp" and the `value` the attribute. This sets the operator to "regexp" and the `value`
to the regular expression. to the regular expression.
* `unique` - Unique accepts a boolean value and can be used to mark a Job or
a Task Group as requiring placement on unique nodes. If the `unique`
constraint is placed on a Job, all of it's Task Groups must be placed on
unique nodes. If the `unique` constraint is placed on a Task Group, then
multiple instances of that Task Group must be placed on unique nodes. This
sets the operator to "unique" if `unique` is set to "true". If set to "false",
the constraint is ignored as this is the default behavior.
Below is a table documenting the variables that can be interpreted: Below is a table documenting the variables that can be interpreted:
<table class="table table-bordered table-striped"> <table class="table table-bordered table-striped">