diff options
author | 2017-08-27 01:32:46 +0100 | |
---|---|---|
committer | 2017-08-26 17:32:46 -0700 | |
commit | 4049ed4f4b85f9f8214a03fc1bb48c579115f9e5 (patch) | |
tree | a7730bf9a282c04b39ecd0066c300be3a2a430cf /middleware/kubernetes/kubernetes.go | |
parent | 01f6e8cba5ab12c5401ef73b0ac9a1d6ac07fcce (diff) | |
download | coredns-4049ed4f4b85f9f8214a03fc1bb48c579115f9e5.tar.gz coredns-4049ed4f4b85f9f8214a03fc1bb48c579115f9e5.tar.zst coredns-4049ed4f4b85f9f8214a03fc1bb48c579115f9e5.zip |
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
Diffstat (limited to 'middleware/kubernetes/kubernetes.go')
-rw-r--r-- | middleware/kubernetes/kubernetes.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/middleware/kubernetes/kubernetes.go b/middleware/kubernetes/kubernetes.go index 4faa818ec..42c68e580 100644 --- a/middleware/kubernetes/kubernetes.go +++ b/middleware/kubernetes/kubernetes.go @@ -40,6 +40,7 @@ type Kubernetes struct { Namespaces map[string]bool podMode string Fallthrough bool + ttl uint32 primaryZoneIndex int interfaceAddrsFunc func() net.IP @@ -55,6 +56,7 @@ func New(zones []string) *Kubernetes { k.interfaceAddrsFunc = func() net.IP { return net.ParseIP("127.0.0.1") } k.podMode = podModeDisabled k.Proxy = proxy.Proxy{} + k.ttl = defaultTTL return k } @@ -382,7 +384,7 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg. if !(match(r.port, p.Name) && match(r.protocol, string(p.Protocol))) { continue } - s := msg.Service{Host: addr.IP, Port: int(p.Port)} + s := msg.Service{Host: addr.IP, Port: int(p.Port), TTL: k.ttl} s.Key = strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name, endpointHostname(addr)}, "/") err = nil @@ -397,7 +399,7 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg. // External service if svc.Spec.ExternalName != "" { - s := msg.Service{Key: strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/"), Host: svc.Spec.ExternalName} + s := msg.Service{Key: strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/"), Host: svc.Spec.ExternalName, TTL: k.ttl} if t, _ := s.HostType(); t == dns.TypeCNAME { s.Key = strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/") services = append(services, s) @@ -416,7 +418,7 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg. err = nil - s := msg.Service{Host: svc.Spec.ClusterIP, Port: int(p.Port)} + s := msg.Service{Host: svc.Spec.ClusterIP, Port: int(p.Port), TTL: k.ttl} s.Key = strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/") services = append(services, s) @@ -455,4 +457,6 @@ const ( Svc = "svc" // Pod is the DNS schema for kubernetes pods Pod = "pod" + // defaultTTL to apply to all answers. + defaultTTL = 5 ) |