diff options
author | 2020-03-30 16:10:07 +0200 | |
---|---|---|
committer | 2020-03-30 16:10:07 +0200 | |
commit | fafb347966beee48643ac3c6b484c0552511d38e (patch) | |
tree | 51aaa3756357bff949141ebf1794cf3d524f0b0c | |
parent | 494227d95fdf05035859c0536a12c52774e1be79 (diff) | |
download | coredns-fafb347966beee48643ac3c6b484c0552511d38e.tar.gz coredns-fafb347966beee48643ac3c6b484c0552511d38e.tar.zst coredns-fafb347966beee48643ac3c6b484c0552511d38e.zip |
More grpc LB tweaks
Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r-- | plugin/traffic/grpc_lb.go | 9 | ||||
-rw-r--r-- | plugin/traffic/traffic.go | 16 |
2 files changed, 17 insertions, 8 deletions
diff --git a/plugin/traffic/grpc_lb.go b/plugin/traffic/grpc_lb.go index 7205caea3..2b27d20a3 100644 --- a/plugin/traffic/grpc_lb.go +++ b/plugin/traffic/grpc_lb.go @@ -1,16 +1,19 @@ package traffic import ( + "fmt" + "github.com/miekg/dns" ) // See https://github.com/grpc/grpc/blob/master/doc/service_config.md for the fields in this proto. // We encode it as json and return it in a TXT field. -var lbTXT = `grpc_config=[{"serviceConfig":{"loadBalancingConfig":[{"eds_experimental":{"LrsLoadReportingServerName":"","Cluster": "xds"}}]}}]` +// TOOD(miek): balancer name should not be hardcoded +var lbTXT = `grpc_config=[{"serviceConfig":{"loadBalancingConfig":[{"eds_experimental":{"Cluster": "xds", "EDSServiceName":"%s", "BalancerName":"xds"}}]}}]` -func txt(z string) []dns.RR { +func txt(z, cluster string) []dns.RR { return []dns.RR{&dns.TXT{ Hdr: dns.RR_Header{Name: z, Rrtype: dns.TypeTXT, Class: dns.ClassINET, Ttl: 5}, - Txt: []string{lbTXT}, + Txt: []string{fmt.Sprintf(lbTXT, cluster)}, }} } diff --git a/plugin/traffic/traffic.go b/plugin/traffic/traffic.go index 8f4f1606d..fbc57d101 100644 --- a/plugin/traffic/traffic.go +++ b/plugin/traffic/traffic.go @@ -70,7 +70,7 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg } if strings.HasPrefix(strings.ToLower(labels[0]), "_grpc_config") { // this is the grpc config blob encoded in a TXT record, see documentation for lbTXT. - m.Answer = txt(state.Zone) + m.Answer = txt(state.Zone, labels[1]) // 1 is the cluster m.Rcode = dns.RcodeSuccess w.WriteMsg(m) return 0, nil @@ -95,10 +95,16 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg w.WriteMsg(m) return 0, nil } - // OK, _grcplb._tcp query; we need to return the endpoint for the mgmt cluster *NOT* the cluster - // we got the query for. This should exist, but we'll check later anyway. - cluster = t.mgmt - sockaddr, _ = t.c.Select(cluster, healthy) + // OK, _grcplb._tcp query; we need to return the endpoint for the cluster in this query + cluster = labels[2] + sockaddr, ok = t.c.Select(cluster, healthy) + if !ok { + // nodata error when this cluster doesn't exist. + m.Ns = soa(state.Zone) + m.Rcode = dns.RcodeSuccess + w.WriteMsg(m) + return 0, nil + } break default: m.Ns = soa(state.Zone) |