diff options
author | 2021-10-27 16:59:21 +0300 | |
---|---|---|
committer | 2021-10-27 09:59:21 -0400 | |
commit | de21fb24367f1586376c48e27de3318c48b59ea3 (patch) | |
tree | 81d4bb476b11c7a4bfc0f92c5af3712b36ac507e /plugin/k8s_external/msg_to_dns.go | |
parent | 6a6905c16c585b1d182b8c6ca3afd6fb2a3f4d24 (diff) | |
download | coredns-de21fb24367f1586376c48e27de3318c48b59ea3.tar.gz coredns-de21fb24367f1586376c48e27de3318c48b59ea3.tar.zst coredns-de21fb24367f1586376c48e27de3318c48b59ea3.zip |
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>
Diffstat (limited to 'plugin/k8s_external/msg_to_dns.go')
-rw-r--r-- | plugin/k8s_external/msg_to_dns.go | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/plugin/k8s_external/msg_to_dns.go b/plugin/k8s_external/msg_to_dns.go index e61adf657..8920f4a00 100644 --- a/plugin/k8s_external/msg_to_dns.go +++ b/plugin/k8s_external/msg_to_dns.go @@ -22,9 +22,7 @@ func (e *External) a(ctx context.Context, services []msg.Service, state request. rr := s.NewCNAME(state.QName(), s.Host) records = append(records, rr) if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeA); err == nil { - for _, rr := range resp.Answer { - records = append(records, rr) - } + records = append(records, resp.Answer...) } 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) records = append(records, rr) if resp, err := e.upstream.Lookup(ctx, state, dns.Fqdn(s.Host), dns.TypeAAAA); err == nil { - for _, rr := range resp.Answer { - records = append(records, rr) - } + records = append(records, resp.Answer...) } case dns.TypeA: @@ -74,7 +70,7 @@ func (e *External) aaaa(ctx context.Context, services []msg.Service, state reque 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{}) // 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() 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: addr := s.Host s.Host = msg.Domain(s.Key) |