mw/kubernetes: add configurable TTL (#995)

* mw/kubernetes: add configurable TTL

Add ttl option to kubernetes. This defaults to 5s but allows
configuration to go up to 3600.

Configure the tests so that a few actually check for the 5s, while the
rest use the TTL of 303 which is ignored by the checking code.

Fixes #935

* fix tests

* and more
This commit is contained in:
Miek Gieben 2017-08-27 01:32:46 +01:00 committed by Yong Tang
parent 01f6e8cba5
commit 4049ed4f4b
6 changed files with 90 additions and 27 deletions

View file

@ -3,6 +3,7 @@ package kubernetes
import (
"errors"
"fmt"
"strconv"
"strings"
"time"
@ -174,6 +175,19 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, dnsControlOpts, error) {
return nil, opts, err
}
k8s.Proxy = proxy.NewLookup(ups)
case "ttl":
args := c.RemainingArgs()
if len(args) == 0 {
return nil, opts, c.ArgErr()
}
t, err := strconv.Atoi(args[0])
if err != nil {
return nil, opts, err
}
if t < 5 || t > 3600 {
return nil, opts, c.Errf("ttl must be in range [5, 3600]: %d", t)
}
k8s.ttl = uint32(t)
default:
return nil, opts, c.Errf("unknown property '%s'", c.Val())
}