Merge branch 'master' of github.com:miekg/coredns

This commit is contained in:
Miek Gieben
2017-02-07 21:30:13 +00:00
5 changed files with 85 additions and 30 deletions

View File

@@ -26,11 +26,15 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
// otherwise delegate to the next in the pipeline.
zone := middleware.Zones(k.Zones).Matches(state.Name())
if zone == "" {
// If this is a PTR request, and a the request is in a defined
// pod/service cidr range, process the request in this middleware,
// otherwise pass to next middleware.
if state.Type() != "PTR" || !k.IsRequestInReverseRange(state) {
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
if state.Type() == "PTR" {
// If this is a PTR request, and a the request is in a defined
// pod/service cidr range, process the request in this middleware,
// otherwise pass to next middleware.
if !k.IsRequestInReverseRange(state) {
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
}
// Set the zone to this specific request.
zone = state.Name()
}
}

View File

@@ -508,7 +508,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
return nil
}
for _, service := range svcList {
if !dnsstrings.StringInSlice(service.Namespace, k.Namespaces) {
if (len(k.Namespaces) > 0) && !dnsstrings.StringInSlice(service.Namespace, k.Namespaces) {
continue
}
if service.Spec.ClusterIP == ip {
@@ -522,7 +522,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
return nil
}
for _, ep := range epList.Items {
if !dnsstrings.StringInSlice(ep.ObjectMeta.Namespace, k.Namespaces) {
if (len(k.Namespaces) > 0) && !dnsstrings.StringInSlice(ep.ObjectMeta.Namespace, k.Namespaces) {
continue
}
for _, eps := range ep.Subsets {

View File

@@ -126,13 +126,7 @@ func (g *google) OnStartup(p *Proxy) error {
new, err := g.bootstrapProxy.Lookup(state, g.endpoint, dns.TypeA)
oldUpstream := *p.Upstreams
oldFrom := ""
var oldEx Exchanger
if len(oldUpstream) > 0 {
oldFrom = oldUpstream[0].From()
oldEx = oldUpstream[0].Exchanger()
}
var oldUpstream Upstream
// ignore errors here, as we want to keep on trying.
if err != nil {
@@ -143,8 +137,13 @@ func (g *google) OnStartup(p *Proxy) error {
log.Printf("[WARNING] Failed to bootstrap A records %q: %s", g.endpoint, err)
}
up := newUpstream(addrs, oldFrom, oldEx)
p.Upstreams = &[]Upstream{up}
if len(*p.Upstreams) > 0 {
oldUpstream = (*p.Upstreams)[0]
up := newUpstream(addrs, oldUpstream.(*staticUpstream))
p.Upstreams = &[]Upstream{up}
} else {
log.Printf("[WARNING] Failed to bootstrap upstreams %q", g.endpoint)
}
}
go func() {
@@ -164,8 +163,11 @@ func (g *google) OnStartup(p *Proxy) error {
continue
}
up := newUpstream(addrs, oldFrom, oldEx)
p.Upstreams = &[]Upstream{up}
// TODO(miek): can this actually happen?
if oldUpstream != nil {
up := newUpstream(addrs, oldUpstream.(*staticUpstream))
p.Upstreams = &[]Upstream{up}
}
}
case <-g.quit:
@@ -195,15 +197,17 @@ func extractAnswer(m *dns.Msg) ([]string, error) {
}
// newUpstream returns an upstream initialized with hosts.
func newUpstream(hosts []string, from string, ex Exchanger) Upstream {
func newUpstream(hosts []string, old *staticUpstream) Upstream {
upstream := &staticUpstream{
from: from,
Hosts: nil,
Policy: &Random{},
Spray: nil,
FailTimeout: 10 * time.Second,
MaxFails: 3,
ex: ex,
from: old.from,
Hosts: nil,
Policy: &Random{},
Spray: nil,
FailTimeout: 10 * time.Second,
MaxFails: 3,
ex: old.ex,
WithoutPathPrefix: old.WithoutPathPrefix,
IgnoredSubDomains: old.IgnoredSubDomains,
}
upstream.Hosts = make([]*UpstreamHost, len(hosts))

View File

@@ -281,11 +281,11 @@ func (u *staticUpstream) Select() *UpstreamHost {
}
func (u *staticUpstream) IsAllowedDomain(name string) bool {
for _, ignoredSubDomain := range u.IgnoredSubDomains {
if dns.Name(name) == dns.Name(u.From()) {
return true
}
if dns.Name(name) == dns.Name(u.From()) {
return true
}
for _, ignoredSubDomain := range u.IgnoredSubDomains {
if middleware.Name(ignoredSubDomain).Matches(name) {
return false
}