Switch over to k8s notification API (#202)
* Merge notification code by @aledbf and update for recent changes. * Fix travis environment to correctly build with k8s.io and forked repositories. * Refactored kubernetes Corefile parser * Added lots of Corefile parsing tests
This commit is contained in:
parent
604d2a3730
commit
6d90b745e0
13 changed files with 609 additions and 237 deletions
|
@ -3,6 +3,7 @@ package kubernetes
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
||||
|
@ -18,6 +19,26 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
|||
return dns.RcodeServerFailure, fmt.Errorf("can only deal with ClassINET")
|
||||
}
|
||||
|
||||
m := new(dns.Msg)
|
||||
m.SetReply(r)
|
||||
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
|
||||
|
||||
// TODO: find an alternative to this block
|
||||
if strings.HasSuffix(state.Name(), arpaSuffix) {
|
||||
ip, _ := extractIP(state.Name())
|
||||
records := k.getServiceRecordForIP(ip, state.Name())
|
||||
if len(records) > 0 {
|
||||
srvPTR := &records[0]
|
||||
m.Answer = append(m.Answer, srvPTR.NewPTR(state.QName(), ip))
|
||||
|
||||
m = dedup(m)
|
||||
state.SizeAndDo(m)
|
||||
m, _ = state.Scrub(m)
|
||||
w.WriteMsg(m)
|
||||
return dns.RcodeSuccess, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Check that query matches one of the zones served by this middleware,
|
||||
// otherwise delegate to the next in the pipeline.
|
||||
zone := middleware.Zones(k.Zones).Matches(state.Name())
|
||||
|
@ -28,10 +49,6 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
|||
return k.Next.ServeDNS(ctx, w, r)
|
||||
}
|
||||
|
||||
m := new(dns.Msg)
|
||||
m.SetReply(r)
|
||||
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
|
||||
|
||||
var (
|
||||
records, extra []dns.RR
|
||||
err error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue