From dc8eab6adc5c682520bb307e3c845e4812a3f7cf Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Wed, 23 Aug 2017 09:30:28 -0400 Subject: [PATCH] Set MaxParallel default to 1 --- api/jobs.go | 8 ++++---- nomad/structs/structs.go | 6 +++--- nomad/structs/structs_test.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/jobs.go b/api/jobs.go index a891ba084..185e10380 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -372,12 +372,12 @@ func (u *UpdateStrategy) Merge(o *UpdateStrategy) { } func (u *UpdateStrategy) Canonicalize() { - if u.MaxParallel == nil { - u.MaxParallel = helper.IntToPtr(0) - } - d := structs.DefaultUpdateStrategy + if u.MaxParallel == nil { + u.MaxParallel = helper.IntToPtr(d.MaxParallel) + } + if u.Stagger == nil { u.Stagger = helper.TimeToPtr(d.Stagger) } diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 18410ecc5..60027b3ac 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2010,7 +2010,7 @@ var ( // jobs with the old policy or for populating field defaults. DefaultUpdateStrategy = &UpdateStrategy{ Stagger: 30 * time.Second, - MaxParallel: 0, + MaxParallel: 1, HealthCheck: UpdateStrategyHealthCheck_Checks, MinHealthyTime: 10 * time.Second, HealthyDeadline: 5 * time.Minute, @@ -2074,8 +2074,8 @@ func (u *UpdateStrategy) Validate() error { multierror.Append(&mErr, fmt.Errorf("Invalid health check given: %q", u.HealthCheck)) } - if u.MaxParallel < 0 { - multierror.Append(&mErr, fmt.Errorf("Max parallel can not be less than zero: %d < 0", u.MaxParallel)) + if u.MaxParallel < 1 { + multierror.Append(&mErr, fmt.Errorf("Max parallel can not be less than one: %d < 1", u.MaxParallel)) } if u.Canary < 0 { multierror.Append(&mErr, fmt.Errorf("Canary count can not be less than zero: %d < 0", u.Canary)) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 56b17e902..cf2f8cb0d 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -1393,7 +1393,7 @@ func TestConstraint_Validate(t *testing.T) { func TestUpdateStrategy_Validate(t *testing.T) { u := &UpdateStrategy{ - MaxParallel: -1, + MaxParallel: 0, HealthCheck: "foo", MinHealthyTime: -10, HealthyDeadline: -15, @@ -1406,7 +1406,7 @@ func TestUpdateStrategy_Validate(t *testing.T) { if !strings.Contains(mErr.Errors[0].Error(), "Invalid health check given") { t.Fatalf("err: %s", err) } - if !strings.Contains(mErr.Errors[1].Error(), "Max parallel can not be less than zero") { + if !strings.Contains(mErr.Errors[1].Error(), "Max parallel can not be less than one") { t.Fatalf("err: %s", err) } if !strings.Contains(mErr.Errors[2].Error(), "Canary count can not be less than zero") {