plugin/k8s_external: fix SRV queries doesn't work with AWS ELB/NLB (#4929)
* fix for issue #4927 Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com> * apply review comments Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com> * apply review comments Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
This commit is contained in:
parent
6a6905c16c
commit
de21fb2436
3 changed files with 24 additions and 10 deletions
|
@ -97,7 +97,7 @@ func (e *External) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
|
||||||
case dns.TypeAAAA:
|
case dns.TypeAAAA:
|
||||||
m.Answer = e.aaaa(ctx, svc, state)
|
m.Answer = e.aaaa(ctx, svc, state)
|
||||||
case dns.TypeSRV:
|
case dns.TypeSRV:
|
||||||
m.Answer, m.Extra = e.srv(svc, state)
|
m.Answer, m.Extra = e.srv(ctx, svc, state)
|
||||||
default:
|
default:
|
||||||
m.Ns = []dns.RR{e.soa(state)}
|
m.Ns = []dns.RR{e.soa(state)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,6 +153,12 @@ var tests = []test.Case{
|
||||||
test.A("svc11.testns.example.com. 5 IN A 1.2.3.4"),
|
test.A("svc11.testns.example.com. 5 IN A 1.2.3.4"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "_http._tcp.svc12.testns.example.com.", Qtype: dns.TypeSRV, Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.SRV("_http._tcp.svc12.testns.example.com. 5 IN SRV 0 100 80 dummy.hostname."),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Qname: "svc12.testns.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeSuccess,
|
Qname: "svc12.testns.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeSuccess,
|
||||||
Answer: []dns.RR{
|
Answer: []dns.RR{
|
||||||
|
|
|
@ -22,9 +22,7 @@ func (e *External) a(ctx context.Context, services []msg.Service, state request.
|
||||||
rr := s.NewCNAME(state.QName(), s.Host)
|
rr := s.NewCNAME(state.QName(), s.Host)
|
||||||
records = append(records, rr)
|
records = append(records, rr)
|
||||||
if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeA); err == nil {
|
if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeA); err == nil {
|
||||||
for _, rr := range resp.Answer {
|
records = append(records, resp.Answer...)
|
||||||
records = append(records, rr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case dns.TypeA:
|
case dns.TypeA:
|
||||||
|
@ -54,9 +52,7 @@ func (e *External) aaaa(ctx context.Context, services []msg.Service, state reque
|
||||||
rr := s.NewCNAME(state.QName(), s.Host)
|
rr := s.NewCNAME(state.QName(), s.Host)
|
||||||
records = append(records, rr)
|
records = append(records, rr)
|
||||||
if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeAAAA); err == nil {
|
if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeAAAA); err == nil {
|
||||||
for _, rr := range resp.Answer {
|
records = append(records, resp.Answer...)
|
||||||
records = append(records, rr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case dns.TypeA:
|
case dns.TypeA:
|
||||||
|
@ -74,7 +70,7 @@ func (e *External) aaaa(ctx context.Context, services []msg.Service, state reque
|
||||||
return records
|
return records
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *External) srv(services []msg.Service, state request.Request) (records, extra []dns.RR) {
|
func (e *External) srv(ctx context.Context, services []msg.Service, state request.Request) (records, extra []dns.RR) {
|
||||||
dup := make(map[item]struct{})
|
dup := make(map[item]struct{})
|
||||||
|
|
||||||
// Looping twice to get the right weight vs priority. This might break because we may drop duplicate SRV records latter on.
|
// Looping twice to get the right weight vs priority. This might break because we may drop duplicate SRV records latter on.
|
||||||
|
@ -111,9 +107,21 @@ func (e *External) srv(services []msg.Service, state request.Request) (records,
|
||||||
what, ip := s.HostType()
|
what, ip := s.HostType()
|
||||||
|
|
||||||
switch what {
|
switch what {
|
||||||
case dns.TypeCNAME:
|
|
||||||
// can't happen
|
|
||||||
|
|
||||||
|
case dns.TypeCNAME:
|
||||||
|
addr := dns.Fqdn(s.Host)
|
||||||
|
srv := s.NewSRV(state.QName(), weight)
|
||||||
|
if ok := isDuplicate(dup, srv.Target, "", srv.Port); !ok {
|
||||||
|
records = append(records, srv)
|
||||||
|
}
|
||||||
|
if ok := isDuplicate(dup, srv.Target, addr, 0); !ok {
|
||||||
|
if resp, err := e.upstream.Lookup(ctx, state, addr, dns.TypeA); err == nil {
|
||||||
|
extra = append(extra, resp.Answer...)
|
||||||
|
}
|
||||||
|
if resp, err := e.upstream.Lookup(ctx, state, addr, dns.TypeAAAA); err == nil {
|
||||||
|
extra = append(extra, resp.Answer...)
|
||||||
|
}
|
||||||
|
}
|
||||||
case dns.TypeA, dns.TypeAAAA:
|
case dns.TypeA, dns.TypeAAAA:
|
||||||
addr := s.Host
|
addr := s.Host
|
||||||
s.Host = msg.Domain(s.Key)
|
s.Host = msg.Domain(s.Key)
|
||||||
|
|
Loading…
Add table
Reference in a new issue