Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-19 09:14:09 +01:00
parent 894ec68487
commit 64d0cfba0c
6 changed files with 20 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ import (
type Traffic struct {
c *xds.Client
id string
health bool
origins []string
Next plugin.Handler
@@ -41,7 +42,7 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
m.SetReply(r)
m.Authoritative = true
sockaddr, ok := t.c.Select(cluster)
sockaddr, ok := t.c.Select(cluster, t.health)
if !ok {
// ok the cluster (which has potentially extra labels), doesn't exist, but we may have a query for endpoint-0.<cluster>.
// check if we have 2 labels and that the first equals endpoint-0.
@@ -55,7 +56,7 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
if strings.HasPrefix(labels[0], "endpoint-") {
// recheck if the cluster exist.
cluster = labels[1]
sockaddr, ok = t.c.Select(cluster)
sockaddr, ok = t.c.Select(cluster, t.health)
if !ok {
m.Ns = soa(state.Zone)
m.Rcode = dns.RcodeNameError
@@ -88,7 +89,7 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
}
m.Answer = []dns.RR{&dns.AAAA{Hdr: dns.RR_Header{Name: state.QName(), Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 5}, AAAA: sockaddr.Address()}}
case dns.TypeSRV:
sockaddrs, _ := t.c.All(cluster)
sockaddrs, _ := t.c.All(cluster, t.health)
for i, sa := range sockaddrs {
target := fmt.Sprintf("endpoint-%d.%s.%s", i, cluster, state.Zone)
@@ -133,7 +134,7 @@ func (t *Traffic) serveEndpoint(ctx context.Context, state request.Request, endp
return 0, nil
}
sockaddrs, _ := t.c.All(cluster)
sockaddrs, _ := t.c.All(cluster, t.health)
if len(sockaddrs) < nr {
m.Ns = soa(state.Zone)
m.Rcode = dns.RcodeNameError