Skip to content

Commit

Permalink
Fix up validation and allow existing unset timeouts to continue to be…
Browse files Browse the repository at this point in the history
… unset
  • Loading branch information
sean- committed Jun 14, 2016
1 parent 18ef97b commit 91bbc5c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,7 @@ func (tg *TaskGroup) GoString() string {
}

const (
// TODO add Consul TTL check
ServiceCheckHTTP = "http"
ServiceCheckTCP = "tcp"
ServiceCheckScript = "script"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 91bbc5c

Please sign in to comment.