From 08b31d4545e9e0519c01c3efc5feaf37d6dd17ee Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 25 Jul 2017 16:30:53 -0700 Subject: [PATCH] Validate that min_healthy_time < healthy_deadline This PR adds a validation check to the update stanza to ensure that the min_healthy_time is feasible. --- nomad/structs/structs.go | 3 +++ nomad/structs/structs_test.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 4e220c018..917616ae6 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -2044,6 +2044,9 @@ func (u *UpdateStrategy) Validate() error { if u.HealthyDeadline <= 0 { multierror.Append(&mErr, fmt.Errorf("Healthy deadline must be greater than zero: %v", u.HealthyDeadline)) } + if u.MinHealthyTime >= u.HealthyDeadline { + multierror.Append(&mErr, fmt.Errorf("Minimum healthy time must be less than healthy deadline: %v > %v", u.MinHealthyTime, u.HealthyDeadline)) + } if u.Stagger <= 0 { multierror.Append(&mErr, fmt.Errorf("Stagger must be greater than zero: %v", u.Stagger)) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 115447efc..4dbff3a4a 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -1314,7 +1314,7 @@ func TestUpdateStrategy_Validate(t *testing.T) { MaxParallel: -1, HealthCheck: "foo", MinHealthyTime: -10, - HealthyDeadline: -10, + HealthyDeadline: -15, AutoRevert: false, Canary: -1, } @@ -1336,6 +1336,9 @@ func TestUpdateStrategy_Validate(t *testing.T) { if !strings.Contains(mErr.Errors[4].Error(), "Healthy deadline must be greater than zero") { t.Fatalf("err: %s", err) } + if !strings.Contains(mErr.Errors[5].Error(), "Minimum healthy time must be less than healthy deadline") { + t.Fatalf("err: %s", err) + } } func TestResource_NetIndex(t *testing.T) {