structs job warnings for taskgroup with mixed auto_promote settings
This commit is contained in:
parent
e027b9001b
commit
21bf9fdf90
|
@ -3481,11 +3481,21 @@ func (j *Job) Warnings() error {
|
||||||
var mErr multierror.Error
|
var mErr multierror.Error
|
||||||
|
|
||||||
// Check the groups
|
// Check the groups
|
||||||
|
ap := 0
|
||||||
for _, tg := range j.TaskGroups {
|
for _, tg := range j.TaskGroups {
|
||||||
if err := tg.Warnings(j); err != nil {
|
if err := tg.Warnings(j); err != nil {
|
||||||
outer := fmt.Errorf("Group %q has warnings: %v", tg.Name, err)
|
outer := fmt.Errorf("Group %q has warnings: %v", tg.Name, err)
|
||||||
mErr.Errors = append(mErr.Errors, outer)
|
mErr.Errors = append(mErr.Errors, outer)
|
||||||
}
|
}
|
||||||
|
if tg.Update.AutoPromote {
|
||||||
|
ap += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check AutoPromote, should be all or none
|
||||||
|
if ap > 0 && ap < len(j.TaskGroups) {
|
||||||
|
err := fmt.Errorf("auto_promote must be true for all groups to enable automatic promotion")
|
||||||
|
mErr.Errors = append(mErr.Errors, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mErr.ErrorOrNil()
|
return mErr.ErrorOrNil()
|
||||||
|
@ -7157,17 +7167,17 @@ func (d *Deployment) RequiresPromotion() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasAutoPromote determines if any taskgroup is marked auto_promote
|
// HasAutoPromote determines if all taskgroups are marked auto_promote
|
||||||
func (d *Deployment) HasAutoPromote() bool {
|
func (d *Deployment) HasAutoPromote() bool {
|
||||||
if d == nil || len(d.TaskGroups) == 0 || d.Status != DeploymentStatusRunning {
|
if d == nil || len(d.TaskGroups) == 0 || d.Status != DeploymentStatusRunning {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, group := range d.TaskGroups {
|
for _, group := range d.TaskGroups {
|
||||||
if group.AutoPromote {
|
if !group.AutoPromote {
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Deployment) GoString() string {
|
func (d *Deployment) GoString() string {
|
||||||
|
|
|
@ -144,6 +144,25 @@ func TestJob_Warnings(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "AutoPromote mixed TaskGroups",
|
||||||
|
Expected: []string{"auto_promote must be true for all groups"},
|
||||||
|
Job: &Job{
|
||||||
|
Type: JobTypeService,
|
||||||
|
TaskGroups: []*TaskGroup{
|
||||||
|
{
|
||||||
|
Update: &UpdateStrategy{
|
||||||
|
AutoPromote: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Update: &UpdateStrategy{
|
||||||
|
AutoPromote: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Reference in a new issue