add update AutoPromote bool

This commit is contained in:
Lang Martin
2019-05-09 09:42:18 -04:00
parent 0643a0162f
commit 9621c073fe
12 changed files with 60 additions and 4 deletions

View File

@@ -376,6 +376,7 @@ type UpdateStrategy struct {
HealthyDeadline *time.Duration `mapstructure:"healthy_deadline"`
ProgressDeadline *time.Duration `mapstructure:"progress_deadline"`
AutoRevert *bool `mapstructure:"auto_revert"`
AutoPromote *bool `mapstructure:"auto_promote"`
Canary *int `mapstructure:"canary"`
}
@@ -433,6 +434,10 @@ func (u *UpdateStrategy) Copy() *UpdateStrategy {
copy.Canary = intToPtr(*u.Canary)
}
if u.AutoPromote != nil {
copy.AutoPromote = boolToPtr(*u.AutoPromote)
}
return copy
}
@@ -472,6 +477,10 @@ func (u *UpdateStrategy) Merge(o *UpdateStrategy) {
if o.Canary != nil {
u.Canary = intToPtr(*o.Canary)
}
if o.AutoPromote != nil {
u.AutoPromote = boolToPtr(*o.AutoPromote)
}
}
func (u *UpdateStrategy) Canonicalize() {

View File

@@ -374,6 +374,7 @@ func TestTaskGroup_Canonicalize_Update(t *testing.T) {
ID: stringToPtr("test"),
Update: &UpdateStrategy{
AutoRevert: boolToPtr(false),
AutoPromote: boolToPtr(false),
Canary: intToPtr(0),
HealthCheck: stringToPtr(""),
HealthyDeadline: timeToPtr(0),

View File

@@ -719,6 +719,7 @@ func ApiTgToStructsTG(taskGroup *api.TaskGroup, tg *structs.TaskGroup) {
HealthyDeadline: *taskGroup.Update.HealthyDeadline,
ProgressDeadline: *taskGroup.Update.ProgressDeadline,
AutoRevert: *taskGroup.Update.AutoRevert,
AutoPromote: *taskGroup.Update.AutoPromote,
Canary: *taskGroup.Update.Canary,
}
}

View File

@@ -1624,6 +1624,7 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
HealthyDeadline: 5 * time.Minute,
ProgressDeadline: 5 * time.Minute,
AutoRevert: true,
AutoPromote: false,
Canary: 1,
},
Meta: map[string]string{

View File

@@ -1602,6 +1602,7 @@ func parseUpdate(result **api.UpdateStrategy, list *ast.ObjectList) error {
"healthy_deadline",
"progress_deadline",
"auto_revert",
"auto_promote",
"canary",
}
if err := helper.CheckHCLKeys(o.Val, valid); err != nil {

View File

@@ -79,6 +79,7 @@ func TestParse(t *testing.T) {
HealthyDeadline: helper.TimeToPtr(10 * time.Minute),
ProgressDeadline: helper.TimeToPtr(10 * time.Minute),
AutoRevert: helper.BoolToPtr(true),
AutoPromote: helper.BoolToPtr(true),
Canary: helper.IntToPtr(1),
},
@@ -163,6 +164,7 @@ func TestParse(t *testing.T) {
HealthyDeadline: helper.TimeToPtr(1 * time.Minute),
ProgressDeadline: helper.TimeToPtr(1 * time.Minute),
AutoRevert: helper.BoolToPtr(false),
AutoPromote: helper.BoolToPtr(false),
Canary: helper.IntToPtr(2),
},
Migrate: &api.MigrateStrategy{

View File

@@ -42,6 +42,7 @@ job "binstore-storagelocker" {
healthy_deadline = "10m"
progress_deadline = "10m"
auto_revert = true
auto_promote = true
canary = 1
}
@@ -84,6 +85,7 @@ job "binstore-storagelocker" {
healthy_deadline = "1m"
progress_deadline = "1m"
auto_revert = false
auto_promote = false
canary = 2
}

View File

@@ -597,9 +597,6 @@ func (w *deploymentWatcher) handleAllocUpdate(allocs []*structs.AllocListStub) (
// We need to create an eval so the job can progress.
if alloc.DeploymentStatus.IsHealthy() && alloc.DeploymentStatus.ModifyIndex > latestEval {
res.createEval = true
if alloc.DeploymentStatus.IsCanary() {
dstate.HealthyCanaries += 1
}
}
// If the group is using a progress deadline, we don't have to do anything.

View File

@@ -594,7 +594,7 @@ func TestWatcher_AutoPromoteDeployment(t *testing.T) {
func() (bool, error) {
ds, _ := m.state.DeploymentsByJobID(ws, j.Namespace, j.ID, true)
d = ds[0]
return 2 == d.TaskGroups["web"].HealthyCanaries, nil
return 2 == d.TaskGroups["web"].HealthyAllocs, nil
},
func(err error) { require.NoError(t, err) },
)

View File

@@ -1977,6 +1977,12 @@ func TestTaskGroupDiff(t *testing.T) {
Type: DiffTypeDeleted,
Name: "Update",
Fields: []*FieldDiff{
{
Type: DiffTypeDeleted,
Name: "AutoPromote",
Old: "false",
New: "",
},
{
Type: DiffTypeDeleted,
Name: "AutoRevert",
@@ -2033,6 +2039,12 @@ func TestTaskGroupDiff(t *testing.T) {
Type: DiffTypeAdded,
Name: "Update",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
Name: "AutoPromote",
Old: "",
New: "false",
},
{
Type: DiffTypeAdded,
Name: "AutoRevert",
@@ -2084,6 +2096,7 @@ func TestTaskGroupDiff(t *testing.T) {
HealthyDeadline: 30 * time.Second,
ProgressDeadline: 29 * time.Second,
AutoRevert: true,
AutoPromote: true,
Canary: 2,
},
},
@@ -2095,6 +2108,7 @@ func TestTaskGroupDiff(t *testing.T) {
HealthyDeadline: 31 * time.Second,
ProgressDeadline: 32 * time.Second,
AutoRevert: false,
AutoPromote: false,
Canary: 1,
},
},
@@ -2105,6 +2119,12 @@ func TestTaskGroupDiff(t *testing.T) {
Type: DiffTypeEdited,
Name: "Update",
Fields: []*FieldDiff{
{
Type: DiffTypeEdited,
Name: "AutoPromote",
Old: "true",
New: "false",
},
{
Type: DiffTypeEdited,
Name: "AutoRevert",
@@ -2163,6 +2183,7 @@ func TestTaskGroupDiff(t *testing.T) {
HealthyDeadline: 30 * time.Second,
ProgressDeadline: 30 * time.Second,
AutoRevert: true,
AutoPromote: true,
Canary: 2,
},
},
@@ -2174,6 +2195,7 @@ func TestTaskGroupDiff(t *testing.T) {
HealthyDeadline: 30 * time.Second,
ProgressDeadline: 30 * time.Second,
AutoRevert: true,
AutoPromote: true,
Canary: 2,
},
},
@@ -2184,6 +2206,12 @@ func TestTaskGroupDiff(t *testing.T) {
Type: DiffTypeEdited,
Name: "Update",
Fields: []*FieldDiff{
{
Type: DiffTypeNone,
Name: "AutoPromote",
Old: "true",
New: "true",
},
{
Type: DiffTypeNone,
Name: "AutoRevert",

View File

@@ -3804,6 +3804,7 @@ var (
HealthyDeadline: 5 * time.Minute,
ProgressDeadline: 10 * time.Minute,
AutoRevert: false,
AutoPromote: false,
Canary: 0,
}
)
@@ -3842,6 +3843,10 @@ type UpdateStrategy struct {
// stable version.
AutoRevert bool
// AutoPromote declares that the deployment should be promoted when all canaries are
// healthy
AutoPromote bool
// Canary is the number of canaries to deploy when a change to the task
// group is detected.
Canary int
@@ -7162,6 +7167,10 @@ type DeploymentState struct {
// reverted on failure
AutoRevert bool
// AutoPromote marks promotion triggered automatically by healthy canaries
// copied from TaskGroup UpdateStrategy in scheduler.reconcile
AutoPromote bool
// ProgressDeadline is the deadline by which an allocation must transition
// to healthy before the deployment is considered failed.
ProgressDeadline time.Duration
@@ -7202,6 +7211,7 @@ func (d *DeploymentState) GoString() string {
base += fmt.Sprintf("\n\tHealthy: %d", d.HealthyAllocs)
base += fmt.Sprintf("\n\tUnhealthy: %d", d.UnhealthyAllocs)
base += fmt.Sprintf("\n\tAutoRevert: %v", d.AutoRevert)
base += fmt.Sprintf("\n\tAutoPromote: %v", d.AutoPromote)
return base
}

View File

@@ -691,6 +691,9 @@ determined. The potential values are:
they can be promoted which unblocks a rolling update of the remaining
allocations at a rate of `max_parallel`.
- `AutoPromote` - Specifies if the job should automatically promote to
the new deployment if all canaries become healthy.
- `Stagger` - Specifies the delay between migrating allocations off nodes marked
for draining.
@@ -704,6 +707,7 @@ An example `Update` block:
"MinHealthyTime": 15000000000,
"HealthyDeadline": 180000000000,
"AutoRevert": false,
"AutoPromote": false,
"Canary": 1
}
}