return all records with matching ip (#3687)

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2020-02-21 01:24:02 -05:00 committed by GitHub
parent ed1841c36f
commit 6ef105ced3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 26 deletions

View file

@ -38,6 +38,7 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service {
return []msg.Service{{Host: domain, TTL: k.ttl}}
}
// If no cluster ips match, search endpoints
var svcs []msg.Service
for _, ep := range k.APIConn.EpIndexReverse(ip) {
if len(k.Namespaces) > 0 && !k.namespaceExposed(ep.Namespace) {
continue
@ -46,10 +47,10 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service {
for _, addr := range eps.Addresses {
if addr.IP == ip {
domain := strings.Join([]string{endpointHostname(addr, k.endpointNameMode), ep.Name, ep.Namespace, Svc, k.primaryZone()}, ".")
return []msg.Service{{Host: domain, TTL: k.ttl}}
svcs = append(svcs, msg.Service{Host: domain, TTL: k.ttl})
}
}
}
}
return nil
return svcs
}

View file

@ -56,16 +56,7 @@ func (APIConnReverseTest) SvcIndexReverse(ip string) []*object.Service {
}
func (APIConnReverseTest) EpIndexReverse(ip string) []*object.Endpoints {
switch ip {
case "10.0.0.100":
case "1234:abcd::1":
case "fd00:77:30::a":
case "fd00:77:30::2:9ba6":
default:
return nil
}
eps := []*object.Endpoints{
{
ep1 := object.Endpoints{
Subsets: []object.EndpointSubset{
{
Addresses: []object.EndpointAddress{
@ -73,6 +64,7 @@ func (APIConnReverseTest) EpIndexReverse(ip string) []*object.Endpoints {
{IP: "1234:abcd::1", Hostname: "ep1b"},
{IP: "fd00:77:30::a", Hostname: "ip6svc1ex"},
{IP: "fd00:77:30::2:9ba6", Hostname: "ip6svc1in"},
{IP: "10.0.0.99", Hostname: "double-ep"}, // this endpoint is used by two services
},
Ports: []object.EndpointPort{
{Port: 80, Protocol: "tcp", Name: "http"},
@ -81,9 +73,34 @@ func (APIConnReverseTest) EpIndexReverse(ip string) []*object.Endpoints {
},
Name: "svc1",
Namespace: "testns",
},
}
return eps
ep2 := object.Endpoints{
Subsets: []object.EndpointSubset{
{
Addresses: []object.EndpointAddress{
{IP: "10.0.0.99", Hostname: "double-ep"}, // this endpoint is used by two services
},
Ports: []object.EndpointPort{
{Port: 80, Protocol: "tcp", Name: "http"},
},
},
},
Name: "svc2",
Namespace: "testns",
}
switch ip {
case "10.0.0.100":
fallthrough
case "1234:abcd::1":
fallthrough
case "fd00:77:30::a":
fallthrough
case "fd00:77:30::2:9ba6":
return []*object.Endpoints{&ep1}
case "10.0.0.99":
return []*object.Endpoints{&ep1, &ep2}
}
return nil
}
func (APIConnReverseTest) GetNodeByName(name string) (*api.Node, error) {
@ -178,6 +195,14 @@ func TestReverse(t *testing.T) {
test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502989566 7200 1800 86400 5"),
},
},
{
Qname: "99.0.0.10.in-addr.arpa.", Qtype: dns.TypePTR,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
test.PTR("99.0.0.10.in-addr.arpa. 5 IN PTR double-ep.svc1.testns.svc.cluster.local."),
test.PTR("99.0.0.10.in-addr.arpa. 5 IN PTR double-ep.svc2.testns.svc.cluster.local."),
},
},
}
ctx := context.TODO()