mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
validate heartbeat in discovery cluster opts
Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
parent
b42ab41b8f
commit
68fde86256
2 changed files with 24 additions and 0 deletions
|
@ -56,6 +56,12 @@ func discoveryOpts(clusterOpts map[string]string) (time.Duration, time.Duration,
|
|||
if err != nil {
|
||||
return time.Duration(0), time.Duration(0), err
|
||||
}
|
||||
|
||||
if h <= 0 {
|
||||
return time.Duration(0), time.Duration(0),
|
||||
fmt.Errorf("discovery.heartbeat must be positive")
|
||||
}
|
||||
|
||||
heartbeat = time.Duration(h) * time.Second
|
||||
ttl = defaultDiscoveryTTLFactor * heartbeat
|
||||
}
|
||||
|
@ -65,6 +71,12 @@ func discoveryOpts(clusterOpts map[string]string) (time.Duration, time.Duration,
|
|||
if err != nil {
|
||||
return time.Duration(0), time.Duration(0), err
|
||||
}
|
||||
|
||||
if t <= 0 {
|
||||
return time.Duration(0), time.Duration(0),
|
||||
fmt.Errorf("discovery.ttl must be positive")
|
||||
}
|
||||
|
||||
ttl = time.Duration(t) * time.Second
|
||||
|
||||
if _, ok := clusterOpts["discovery.heartbeat"]; !ok {
|
||||
|
|
|
@ -18,6 +18,18 @@ func TestDiscoveryOpts(t *testing.T) {
|
|||
t.Fatalf("discovery.ttl == discovery.heartbeat must fail")
|
||||
}
|
||||
|
||||
clusterOpts = map[string]string{"discovery.heartbeat": "-10", "discovery.ttl": "10"}
|
||||
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
||||
if err == nil {
|
||||
t.Fatalf("negative discovery.heartbeat must fail")
|
||||
}
|
||||
|
||||
clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "-10"}
|
||||
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
||||
if err == nil {
|
||||
t.Fatalf("negative discovery.ttl must fail")
|
||||
}
|
||||
|
||||
clusterOpts = map[string]string{"discovery.heartbeat": "invalid"}
|
||||
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in a new issue