warn destructive update only when count > 1 (#13103)

This commit is contained in:
Yan 2022-09-02 19:30:06 +00:00 committed by GitHub
parent b5cf358212
commit 6e927fa125
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

3
.changelog/13103.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
cli: warn destructive update only when count is greater than 1
```

View File

@ -6764,7 +6764,7 @@ func (tg *TaskGroup) Warnings(j *Job) error {
// Validate the update strategy // Validate the update strategy
if u := tg.Update; u != nil { if u := tg.Update; u != nil {
// Check the counts are appropriate // 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, mErr.Errors = append(mErr.Errors,
fmt.Errorf("Update max parallel count is greater than task group count (%d > %d). "+ 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)) "A destructive change would result in the simultaneous replacement of all allocations.", u.MaxParallel, tg.Count))

View File

@ -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 { for _, c := range cases {