diff --git a/api/tasks.go b/api/tasks.go index 3e0bc40af72..291971b719f 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -82,9 +82,9 @@ func (r *RestartPolicy) Merge(rp *RestartPolicy) { // CheckRestart describes if and when a task should be restarted based on // failing health checks. type CheckRestart struct { - Limit int `mapstructure:"limit"` - Grace time.Duration `mapstructure:"grace_period"` - IgnoreWarnings bool `mapstructure:"ignore_warnings"` + Limit int `mapstructure:"limit"` + Grace *time.Duration `mapstructure:"grace_period"` + IgnoreWarnings bool `mapstructure:"ignore_warnings"` } // The ServiceCheck data model represents the consul health check that @@ -107,6 +107,14 @@ type ServiceCheck struct { CheckRestart *CheckRestart `mapstructure:"check_restart"` } +func (c *ServiceCheck) Canonicalize() { + if c.CheckRestart != nil { + if c.CheckRestart.Grace == nil { + c.CheckRestart.Grace = helper.TimeToPtr(1 * time.Second) + } + } +} + // The Service model represents a Consul service definition type Service struct { Id string @@ -127,6 +135,10 @@ func (s *Service) Canonicalize(t *Task, tg *TaskGroup, job *Job) { if s.AddressMode == "" { s.AddressMode = "auto" } + + for _, c := range s.Checks { + c.Canonicalize() + } } // EphemeralDisk is an ephemeral disk object diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 8bfc8a1895a..7c7b0089b76 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -688,7 +688,7 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) { if service.CheckRestart != nil { structsTask.Services[i].CheckRestart = &structs.CheckRestart{ Limit: service.CheckRestart.Limit, - Grace: service.CheckRestart.Grace, + Grace: *service.CheckRestart.Grace, IgnoreWarnings: service.CheckRestart.IgnoreWarnings, } } @@ -714,7 +714,7 @@ func ApiTaskToStructsTask(apiTask *api.Task, structsTask *structs.Task) { if check.CheckRestart != nil { structsTask.Services[i].Checks[j].CheckRestart = &structs.CheckRestart{ Limit: check.CheckRestart.Limit, - Grace: check.CheckRestart.Grace, + Grace: *check.CheckRestart.Grace, IgnoreWarnings: check.CheckRestart.IgnoreWarnings, } }