diff options
author | 2022-07-06 13:55:15 -0400 | |
---|---|---|
committer | 2022-07-06 13:55:15 -0400 | |
commit | e80d696502863f2e35099e6e366bb00418c28d80 (patch) | |
tree | 99e2c372668b6f7e73ab736ecb551b6997ccdd8e /plugin/k8s_external/external_test.go | |
parent | d903a963eeb3454996846811fb850ceb8c4fea81 (diff) | |
download | coredns-e80d696502863f2e35099e6e366bb00418c28d80.tar.gz coredns-e80d696502863f2e35099e6e366bb00418c28d80.tar.zst coredns-e80d696502863f2e35099e6e366bb00418c28d80.zip |
plugin/k8s_external: Add support for PTR requests (#5435)
* Exclude External IP addresses from being added to the existing kubernetes' plugin IP->Service index
* Add support for PTR requests on External IPs of Services to the k8s_external plugin
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/k8s_external/external_test.go')
-rw-r--r-- | plugin/k8s_external/external_test.go | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/plugin/k8s_external/external_test.go b/plugin/k8s_external/external_test.go index 558c894f6..22ef08cc1 100644 --- a/plugin/k8s_external/external_test.go +++ b/plugin/k8s_external/external_test.go @@ -20,7 +20,7 @@ func TestExternal(t *testing.T) { k.APIConn = &external{} e := New() - e.Zones = []string{"example.com."} + e.Zones = []string{"example.com.", "in-addr.arpa."} e.Next = test.NextHandler(dns.RcodeSuccess, nil) e.externalFunc = k.External e.externalAddrFunc = externalAddress // internal test function @@ -49,12 +49,33 @@ func TestExternal(t *testing.T) { t.Error("Expected authoritative answer") } if err = test.SortAndCheck(resp, tc); err != nil { - t.Error(err) + t.Errorf("Test %d: %v", i, err) } } } var tests = []test.Case{ + // PTR reverse lookup + { + Qname: "4.3.2.1.in-addr.arpa.", Qtype: dns.TypePTR, Rcode: dns.RcodeSuccess, + Answer: []dns.RR{ + test.PTR("4.3.2.1.in-addr.arpa. 5 IN PTR svc1.testns.example.com."), + }, + }, + // Bad PTR reverse lookup using existing service name + { + Qname: "svc1.testns.example.com.", Qtype: dns.TypePTR, Rcode: dns.RcodeSuccess, + Ns: []dns.RR{ + test.SOA("example.com. 5 IN SOA ns1.dns.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"), + }, + }, + // Bad PTR reverse lookup using non-existing service name + { + Qname: "not-existing.testns.example.com.", Qtype: dns.TypePTR, Rcode: dns.RcodeNameError, + Ns: []dns.RR{ + test.SOA("example.com. 5 IN SOA ns1.dns.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"), + }, + }, // A Service { Qname: "svc1.testns.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeSuccess, @@ -155,7 +176,7 @@ var tests = []test.Case{ { Qname: "svc11.testns.example.com.", Qtype: dns.TypeA, Rcode: dns.RcodeSuccess, Answer: []dns.RR{ - test.A("svc11.testns.example.com. 5 IN A 1.2.3.4"), + test.A("svc11.testns.example.com. 5 IN A 2.3.4.5"), }, }, { @@ -164,7 +185,7 @@ var tests = []test.Case{ test.SRV("_http._tcp.svc11.testns.example.com. 5 IN SRV 0 100 80 svc11.testns.example.com."), }, Extra: []dns.RR{ - test.A("svc11.testns.example.com. 5 IN A 1.2.3.4"), + test.A("svc11.testns.example.com. 5 IN A 2.3.4.5"), }, }, { @@ -173,7 +194,7 @@ var tests = []test.Case{ test.SRV("svc11.testns.example.com. 5 IN SRV 0 100 80 svc11.testns.example.com."), }, Extra: []dns.RR{ - test.A("svc11.testns.example.com. 5 IN A 1.2.3.4"), + test.A("svc11.testns.example.com. 5 IN A 2.3.4.5"), }, }, // svc12 @@ -211,6 +232,20 @@ func (external) GetNodeByName(ctx context.Context, name string) (*api.Node, erro func (external) SvcIndex(s string) []*object.Service { return svcIndexExternal[s] } func (external) PodIndex(string) []*object.Pod { return nil } +func (external) SvcExtIndexReverse(ip string) (result []*object.Service) { + for _, svcs := range svcIndexExternal { + for _, svc := range svcs { + for _, exIp := range svc.ExternalIPs { + if exIp != ip { + continue + } + result = append(result, svc) + } + } + } + return result +} + func (external) GetNamespaceByName(name string) (*object.Namespace, error) { return &object.Namespace{ Name: name, @@ -243,7 +278,7 @@ var svcIndexExternal = map[string][]*object.Service{ Name: "svc11", Namespace: "testns", Type: api.ServiceTypeLoadBalancer, - ExternalIPs: []string{"1.2.3.4"}, + ExternalIPs: []string{"2.3.4.5"}, Ports: []api.ServicePort{{Name: "http", Protocol: "tcp", Port: 80}}, }, }, |