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

Don't merge empty update from job into task groups #3139

Merged
merged 2 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

BUG FIXES:
* 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)
}