Skip to content

Commit

Permalink
Allow distinct_host to have L/RTarget set
Browse files Browse the repository at this point in the history
This PR removes validation that could break job backwards compatibility.
The targets are ignored so there is no side effects.

Fixes #3130
  • Loading branch information
dadgar committed Aug 30, 2017
1 parent aa9bb33 commit 23dfbfa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
6 changes: 0 additions & 6 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3973,12 +3973,6 @@ func (c *Constraint) Validate() error {
switch c.Operand {
case ConstraintDistinctHosts:
requireLtarget = false
if c.RTarget != "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Distinct hosts constraint doesn't allow RTarget. Got %q", c.RTarget))
}
if c.LTarget != "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Distinct hosts constraint doesn't allow LTarget. Got %q", c.LTarget))
}
case ConstraintSetContains:
if c.RTarget == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Set contains constraint requires an RTarget"))
Expand Down
12 changes: 4 additions & 8 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,14 +1353,10 @@ func TestConstraint_Validate(t *testing.T) {

// Perform distinct_hosts validation
c.Operand = ConstraintDistinctHosts
c.RTarget = "foo"
err = c.Validate()
mErr = err.(*multierror.Error)
if !strings.Contains(mErr.Errors[0].Error(), "doesn't allow RTarget") {
t.Fatalf("err: %s", err)
}
if !strings.Contains(mErr.Errors[1].Error(), "doesn't allow LTarget") {
t.Fatalf("err: %s", err)
c.LTarget = ""
c.RTarget = ""
if err := c.Validate(); err != nil {
t.Fatalf("expected valid constraint: %v", err)
}

// Perform set_contains validation
Expand Down

0 comments on commit 23dfbfa

Please sign in to comment.