From 23dfbfa52a15482ae8fd7a25426266f1e6e4bf86 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 30 Aug 2017 10:30:01 -0700 Subject: [PATCH 1/2] Allow distinct_host to have L/RTarget set This PR removes validation that could break job backwards compatibility. The targets are ignored so there is no side effects. Fixes https://github.com/hashicorp/nomad/issues/3130 --- nomad/structs/structs.go | 6 ------ nomad/structs/structs_test.go | 12 ++++-------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 03e4701d26c..f62b5e89a8e 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -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")) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index cf2f8cb0da2..cfe7c215875 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -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 From 84c86513b9d8c88519f596ab46caf413149be99f Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 30 Aug 2017 10:33:03 -0700 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b2fb4696ff..1f9241b7ef2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ BUG FIXES: another job [GH-3120] * cli: Fix setting of TLSServerName for node API Client. This fixes an issue of contacting nodes that are using TLS [GH-3127] + * jobspec: Allow distinct_host constraint to have L/RTarget set [GH-3136] ## 0.6.2 (August 28, 2017)