plugin/kubernetes: Handle multiple local IPs and bind (#3208)
* use all local IPs * mult/bind ips * gofmt + boundIPs fix * fix no matching endpoint case * don't duplicate NS records in answer * fix answer dedup * fix comment * add multi local ip test case
This commit is contained in:
parent
d79562842a
commit
630d3d60b9
8 changed files with 91 additions and 51 deletions
|
@ -310,20 +310,28 @@ func TestServicesAuthority(t *testing.T) {
|
|||
key string
|
||||
}
|
||||
type svcTest struct {
|
||||
interfaceAddrs func() net.IP
|
||||
qname string
|
||||
qtype uint16
|
||||
answer *svcAns
|
||||
localIPs []net.IP
|
||||
qname string
|
||||
qtype uint16
|
||||
answer []svcAns
|
||||
}
|
||||
tests := []svcTest{
|
||||
{interfaceAddrs: func() net.IP { return net.ParseIP("127.0.0.1") }, qname: "ns.dns.interwebs.test.", qtype: dns.TypeA, answer: &svcAns{host: "127.0.0.1", key: "/" + coredns + "/test/interwebs/dns/ns"}},
|
||||
{interfaceAddrs: func() net.IP { return net.ParseIP("127.0.0.1") }, qname: "ns.dns.interwebs.test.", qtype: dns.TypeAAAA},
|
||||
{interfaceAddrs: func() net.IP { return net.ParseIP("::1") }, qname: "ns.dns.interwebs.test.", qtype: dns.TypeA},
|
||||
{interfaceAddrs: func() net.IP { return net.ParseIP("::1") }, qname: "ns.dns.interwebs.test.", qtype: dns.TypeAAAA, answer: &svcAns{host: "::1", key: "/" + coredns + "/test/interwebs/dns/ns"}},
|
||||
{localIPs: []net.IP{net.ParseIP("1.2.3.4")}, qname: "ns.dns.interwebs.test.", qtype: dns.TypeA, answer: []svcAns{{host: "1.2.3.4", key: "/" + coredns + "/test/interwebs/dns/ns"}}},
|
||||
{localIPs: []net.IP{net.ParseIP("1.2.3.4")}, qname: "ns.dns.interwebs.test.", qtype: dns.TypeAAAA},
|
||||
{localIPs: []net.IP{net.ParseIP("1:2::3:4")}, qname: "ns.dns.interwebs.test.", qtype: dns.TypeA},
|
||||
{localIPs: []net.IP{net.ParseIP("1:2::3:4")}, qname: "ns.dns.interwebs.test.", qtype: dns.TypeAAAA, answer: []svcAns{{host: "1:2::3:4", key: "/" + coredns + "/test/interwebs/dns/ns"}}},
|
||||
{
|
||||
localIPs: []net.IP{net.ParseIP("1.2.3.4"), net.ParseIP("1:2::3:4")},
|
||||
qname: "ns.dns.interwebs.test.",
|
||||
qtype: dns.TypeNS, answer: []svcAns{
|
||||
{host: "1.2.3.4", key: "/" + coredns + "/test/interwebs/dns/ns"},
|
||||
{host: "1:2::3:4", key: "/" + coredns + "/test/interwebs/dns/ns"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
k.interfaceAddrsFunc = test.interfaceAddrs
|
||||
k.localIPs = test.localIPs
|
||||
|
||||
state := request.Request{
|
||||
Req: &dns.Msg{Question: []dns.Question{{Name: test.qname, Qtype: test.qtype}}},
|
||||
|
@ -334,7 +342,7 @@ func TestServicesAuthority(t *testing.T) {
|
|||
t.Errorf("Test %d: got error '%v'", i, e)
|
||||
continue
|
||||
}
|
||||
if test.answer != nil && len(svcs) != 1 {
|
||||
if test.answer != nil && len(svcs) != len(test.answer) {
|
||||
t.Errorf("Test %d, expected 1 answer, got %v", i, len(svcs))
|
||||
continue
|
||||
}
|
||||
|
@ -347,11 +355,13 @@ func TestServicesAuthority(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
if test.answer.host != svcs[0].Host {
|
||||
t.Errorf("Test %d, expected host '%v', got '%v'", i, test.answer.host, svcs[0].Host)
|
||||
}
|
||||
if test.answer.key != svcs[0].Key {
|
||||
t.Errorf("Test %d, expected key '%v', got '%v'", i, test.answer.key, svcs[0].Key)
|
||||
for i, answer := range test.answer {
|
||||
if answer.host != svcs[i].Host {
|
||||
t.Errorf("Test %d, expected host '%v', got '%v'", i, answer.host, svcs[i].Host)
|
||||
}
|
||||
if answer.key != svcs[i].Key {
|
||||
t.Errorf("Test %d, expected key '%v', got '%v'", i, answer.key, svcs[i].Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue