Skip to content

Commit

Permalink
Merge pull request #3139 from hashicorp/b-copied-update
Browse files Browse the repository at this point in the history
Don't merge empty update from job into task groups
  • Loading branch information
dadgar committed Aug 30, 2017
2 parents 98bb9a2 + d0139c0 commit 2f10b9f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BUG FIXES:
* api: Search handles prefix longer than allowed UUIDs [GH-3138]
* api: Search endpoint handles even UUID prefixes with hyphens [GH-3120]
* api: Don't merge empty update stanza from job into task groups [GH-3139]
* cli: All status commands handle even UUID prefixes with hyphens [GH-3122]
* cli: Fix autocompletion of paths that include directories on zsh [GH-3129]
* cli: Status command honors exact job match even when it is the prefix of
Expand Down
37 changes: 37 additions & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,43 @@ func (u *UpdateStrategy) Canonicalize() {
}
}

// Empty returns whether the UpdateStrategy is empty or has user defined values.
func (u *UpdateStrategy) Empty() bool {
if u == nil {
return true
}

if u.Stagger != nil && *u.Stagger != 0 {
return false
}

if u.MaxParallel != nil && *u.MaxParallel != 0 {
return false
}

if u.HealthCheck != nil && *u.HealthCheck != "" {
return false
}

if u.MinHealthyTime != nil && *u.MinHealthyTime != 0 {
return false
}

if u.HealthyDeadline != nil && *u.HealthyDeadline != 0 {
return false
}

if u.AutoRevert != nil && *u.AutoRevert {
return false
}

if u.Canary != nil && *u.Canary != 0 {
return false
}

return true
}

// PeriodicConfig is for serializing periodic config for a job.
type PeriodicConfig struct {
Enabled *bool
Expand Down
4 changes: 2 additions & 2 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ func (g *TaskGroup) Canonicalize(job *Job) {
jc := job.Update.Copy()
jc.Merge(g.Update)
g.Update = jc
} else if ju {
// Inherit the jobs
} else if ju && !job.Update.Empty() {
// Inherit the jobs as long as it is non-empty.
jc := job.Update.Copy()
g.Update = jc
}
Expand Down
23 changes: 23 additions & 0 deletions api/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/hashicorp/nomad/helper"
"github.com/stretchr/testify/assert"
)

func TestTaskGroup_NewTaskGroup(t *testing.T) {
Expand Down Expand Up @@ -243,3 +244,25 @@ func TestTask_Artifact(t *testing.T) {
t.Errorf("expected local/foo.txt but found %q", *a.RelativeDest)
}
}

// Ensures no regression on https://github.com/hashicorp/nomad/issues/3132
func TestTaskGroup_Canonicalize_Update(t *testing.T) {
job := &Job{
ID: helper.StringToPtr("test"),
Update: &UpdateStrategy{
AutoRevert: helper.BoolToPtr(false),
Canary: helper.IntToPtr(0),
HealthCheck: helper.StringToPtr(""),
HealthyDeadline: helper.TimeToPtr(0),
MaxParallel: helper.IntToPtr(0),
MinHealthyTime: helper.TimeToPtr(0),
Stagger: helper.TimeToPtr(0),
},
}
job.Canonicalize()
tg := &TaskGroup{
Name: helper.StringToPtr("foo"),
}
tg.Canonicalize(job)
assert.Nil(t, tg.Update)
}

0 comments on commit 2f10b9f

Please sign in to comment.