diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index b7e25a3da5da..cb97d2908949 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1482,6 +1482,7 @@ func (tg *TaskGroup) GoString() string { } const ( + // TODO add Consul TTL check ServiceCheckHTTP = "http" ServiceCheckTCP = "tcp" ServiceCheckScript = "script" @@ -1522,26 +1523,32 @@ func (sc *ServiceCheck) Copy() *ServiceCheck { func (sc *ServiceCheck) validate() error { switch strings.ToLower(sc.Type) { case ServiceCheckTCP: + if sc.Timeout > 0 && sc.Timeout <= minCheckTimeout { + return fmt.Errorf("timeout %v is lower than required minimum timeout %v", sc.Timeout, minCheckInterval) + } case ServiceCheckHTTP: if sc.Path == "" { return fmt.Errorf("http type must have a valid http path") } + + if sc.Timeout > 0 && sc.Timeout <= minCheckTimeout { + return fmt.Errorf("timeout %v is lower than required minimum timeout %v", sc.Timeout, minCheckInterval) + } case ServiceCheckScript: if sc.Command == "" { return fmt.Errorf("script type must have a valid script path") } + + // TODO: enforce timeout on the Client side and reenable + // validation. default: return fmt.Errorf(`invalid type (%+q), must be one of "http", "tcp", or "script" type`, sc.Type) } - if sc.Interval <= minCheckInterval { + if sc.Interval > 0 && sc.Interval <= minCheckInterval { return fmt.Errorf("interval (%v) can not be lower than %v", sc.Interval, minCheckInterval) } - if sc.Timeout <= minCheckTimeout { - return fmt.Errorf("timeout %v is lower than required minimum timeout %v", sc.Timeout, minCheckInterval) - } - return nil }