diff --git a/.changelog/13103.txt b/.changelog/13103.txt new file mode 100644 index 00000000000..1f3a3d42369 --- /dev/null +++ b/.changelog/13103.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: warn destructive update only when count is greater than 1 +``` diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 0571fa02181..b5e5a25bf5e 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -6764,7 +6764,7 @@ func (tg *TaskGroup) Warnings(j *Job) error { // Validate the update strategy if u := tg.Update; u != nil { // Check the counts are appropriate - if u.MaxParallel > tg.Count && !(j.IsMultiregion() && tg.Count == 0) { + if tg.Count > 1 && u.MaxParallel > tg.Count && !(j.IsMultiregion() && tg.Count == 0) { mErr.Errors = append(mErr.Errors, fmt.Errorf("Update max parallel count is greater than task group count (%d > %d). "+ "A destructive change would result in the simultaneous replacement of all allocations.", u.MaxParallel, tg.Count)) diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 973dc8d1d6e..e2f6cbc3c53 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -255,6 +255,36 @@ func TestJob_Warnings(t *testing.T) { }, }, }, + { + Name: "Update.MaxParallel warning", + Expected: []string{"Update max parallel count is greater than task group count (5 > 2). A destructive change would result in the simultaneous replacement of all allocations."}, + Job: &Job{ + Type: JobTypeService, + TaskGroups: []*TaskGroup{ + { + Count: 2, + Update: &UpdateStrategy{ + MaxParallel: 5, + }, + }, + }, + }, + }, + { + Name: "Update.MaxParallel no warning", + Expected: []string{}, + Job: &Job{ + Type: JobTypeService, + TaskGroups: []*TaskGroup{ + { + Count: 1, + Update: &UpdateStrategy{ + MaxParallel: 5, + }, + }, + }, + }, + }, } for _, c := range cases {