Skip to content

Commit

Permalink
Honor value for distinct_hosts constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycub committed Apr 17, 2023
1 parent ed0dfd2 commit 37d9018
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion jobspec2/hcl_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ func decodeConstraint(body hcl.Body, ctx *hcl.EvalContext, val interface{}) hcl.
c.RTarget = constraint
}

if d := v.GetAttr(api.ConstraintDistinctHosts); !d.IsNull() && d.True() {
// The shortcut form of the distinct_hosts constraint is a cty.Bool
// so it can not use the `attr` func defined earlier
if d := v.GetAttr(api.ConstraintDistinctHosts); !d.IsNull() {
c.Operand = api.ConstraintDistinctHosts
c.RTarget = fmt.Sprint(d.True())
}

if property := attr(api.ConstraintDistinctProperty); property != "" {
Expand Down
9 changes: 8 additions & 1 deletion scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,14 @@ func (iter *DistinctHostsIterator) SetJob(job *structs.Job) {
func (iter *DistinctHostsIterator) hasDistinctHostsConstraint(constraints []*structs.Constraint) bool {
for _, con := range constraints {
if con.Operand == structs.ConstraintDistinctHosts {
return true
// Maintain the old behavior around unset RTargets
if con.RTarget == "" {
return true
}
enabled, err := strconv.ParseBool(con.RTarget)
// If the value is unparsable as a boolean, fall back to the old behavior
// of enforcing the constraint when it appears.
return err != nil || enabled
}
}

Expand Down

0 comments on commit 37d9018

Please sign in to comment.