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 Host constraint accepts bool or string. #501

Merged
merged 2 commits into from
Nov 25, 2015
Merged
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions jobspec/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,17 @@ func parseConstraints(result *[]*structs.Constraint, list *ast.ObjectList) error
}

if value, ok := m[structs.ConstraintDistinctHosts]; ok {
enabled, err := strconv.ParseBool(value.(string))
if err != nil {
return err
var enabled bool
var err error
switch value.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this in a method like toBool? I think it would read better.

case string:
if enabled, err = strconv.ParseBool(value.(string)); err != nil {
return err
}
case bool:
enabled = value.(bool)
default:
return fmt.Errorf("distinct_hosts should be set to true or false; got %v", value)
}

// If it is not enabled, skip the constraint.
Expand Down