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>
This commit is contained in:
parent
d903a963ee
commit
e80d696502
12 changed files with 163 additions and 44 deletions
|
@ -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}},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue