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

deployments: canary=0 is implicitly autopromote #11013

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4302,19 +4302,22 @@ func (j *Job) Warnings() error {
var mErr multierror.Error

// Check the groups
ap := 0
hasAutoPromote, allAutoPromote := false, true

for _, tg := range j.TaskGroups {
if err := tg.Warnings(j); err != nil {
outer := fmt.Errorf("Group %q has warnings: %v", tg.Name, err)
mErr.Errors = append(mErr.Errors, outer)
}
if tg.Update != nil && tg.Update.AutoPromote {
ap += 1

if u := tg.Update; u != nil {
hasAutoPromote = hasAutoPromote || u.AutoPromote
allAutoPromote = allAutoPromote && (u.Canary == 0 || u.AutoPromote)
notnoop marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Check AutoPromote, should be all or none
if ap > 0 && ap < len(j.TaskGroups) {
if hasAutoPromote && !allAutoPromote {
err := fmt.Errorf("auto_promote must be true for all groups to enable automatic promotion")
mErr.Errors = append(mErr.Errors, err)
}
Expand Down Expand Up @@ -8877,7 +8880,7 @@ func (d *Deployment) HasAutoPromote() bool {
return false
}
for _, group := range d.TaskGroups {
if !group.AutoPromote {
if group.DesiredCanaries > 0 && !group.AutoPromote {
return false
}
}
Expand Down
21 changes: 21 additions & 0 deletions nomad/structs/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ func TestJob_Warnings(t *testing.T) {
{
Update: &UpdateStrategy{
AutoPromote: false,
Canary: 1,
},
},
},
},
},
{
Name: "no error for mixed but implied AutoPromote",
Expected: []string{},
Job: &Job{
Type: JobTypeService,
TaskGroups: []*TaskGroup{
{
Update: &UpdateStrategy{
AutoPromote: true,
},
},
{
Update: &UpdateStrategy{
AutoPromote: false,
Canary: 0,
},
},
},
Expand Down