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

distinct_property constraint #2418

Merged
merged 8 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions jobspec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,13 @@ func parseConstraints(result *[]*api.Constraint, list *ast.ObjectList) error {
// Check for invalid keys
valid := []string{
"attribute",
"distinct_hosts",
"distinct_property",
"operator",
"value",
"version",
"regexp",
"distinct_hosts",
"set_contains",
"value",
"version",
}
if err := checkHCLKeys(o.Val, valid); err != nil {
return err
Expand Down Expand Up @@ -467,6 +468,11 @@ func parseConstraints(result *[]*api.Constraint, list *ast.ObjectList) error {
m["Operand"] = structs.ConstraintDistinctHosts
}

if property, ok := m[structs.ConstraintDistinctProperty]; ok {
m["Operand"] = structs.ConstraintDistinctProperty
m["LTarget"] = property
}

// Build the constraint
var c api.Constraint
if err := mapstructure.WeakDecode(m, &c); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ func TestParse(t *testing.T) {
false,
},

{
"distinctProperty-constraint.hcl",
&api.Job{
ID: helper.StringToPtr("foo"),
Name: helper.StringToPtr("foo"),
Constraints: []*api.Constraint{
&api.Constraint{
Operand: structs.ConstraintDistinctProperty,
LTarget: "${meta.rack}",
},
},
},
false,
},

{
"periodic-cron.hcl",
&api.Job{
Expand Down
5 changes: 5 additions & 0 deletions jobspec/test-fixtures/distinctProperty-constraint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
job "foo" {
constraint {
distinct_property = "${meta.rack}"
}
}
9 changes: 5 additions & 4 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3189,10 +3189,11 @@ func (ta *TaskArtifact) Validate() error {
}

const (
ConstraintDistinctHosts = "distinct_hosts"
ConstraintRegex = "regexp"
ConstraintVersion = "version"
ConstraintSetContains = "set_contains"
ConstraintDistinctProperty = "distinct_property"
ConstraintDistinctHosts = "distinct_hosts"
ConstraintRegex = "regexp"
ConstraintVersion = "version"
ConstraintSetContains = "set_contains"
)

// Constraints are used to restrict placement options.
Expand Down
Loading