Commit 6ef105ce authored by Chris O'Haver's avatar Chris O'Haver Committed by GitHub

return all records with matching ip (#3687)

Signed-off-by: default avatarChris O'Haver <cohaver@infoblox.com>
parent ed1841c3
...@@ -38,6 +38,7 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service { ...@@ -38,6 +38,7 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service {
return []msg.Service{{Host: domain, TTL: k.ttl}} return []msg.Service{{Host: domain, TTL: k.ttl}}
} }
// If no cluster ips match, search endpoints // If no cluster ips match, search endpoints
var svcs []msg.Service
for _, ep := range k.APIConn.EpIndexReverse(ip) { for _, ep := range k.APIConn.EpIndexReverse(ip) {
if len(k.Namespaces) > 0 && !k.namespaceExposed(ep.Namespace) { if len(k.Namespaces) > 0 && !k.namespaceExposed(ep.Namespace) {
continue continue
...@@ -46,10 +47,10 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service { ...@@ -46,10 +47,10 @@ func (k *Kubernetes) serviceRecordForIP(ip, name string) []msg.Service {
for _, addr := range eps.Addresses { for _, addr := range eps.Addresses {
if addr.IP == ip { if addr.IP == ip {
domain := strings.Join([]string{endpointHostname(addr, k.endpointNameMode), ep.Name, ep.Namespace, Svc, k.primaryZone()}, ".") 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
} }
...@@ -56,34 +56,51 @@ func (APIConnReverseTest) SvcIndexReverse(ip string) []*object.Service { ...@@ -56,34 +56,51 @@ func (APIConnReverseTest) SvcIndexReverse(ip string) []*object.Service {
} }
func (APIConnReverseTest) EpIndexReverse(ip string) []*object.Endpoints { func (APIConnReverseTest) EpIndexReverse(ip string) []*object.Endpoints {
ep1 := object.Endpoints{
Subsets: []object.EndpointSubset{
{
Addresses: []object.EndpointAddress{
{IP: "10.0.0.100", Hostname: "ep1a"},
{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"},
},
},
},
Name: "svc1",
Namespace: "testns",
}
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 { switch ip {
case "10.0.0.100": case "10.0.0.100":
fallthrough
case "1234:abcd::1": case "1234:abcd::1":
fallthrough
case "fd00:77:30::a": case "fd00:77:30::a":
fallthrough
case "fd00:77:30::2:9ba6": case "fd00:77:30::2:9ba6":
default: return []*object.Endpoints{&ep1}
return nil case "10.0.0.99":
return []*object.Endpoints{&ep1, &ep2}
} }
eps := []*object.Endpoints{ return nil
{
Subsets: []object.EndpointSubset{
{
Addresses: []object.EndpointAddress{
{IP: "10.0.0.100", Hostname: "ep1a"},
{IP: "1234:abcd::1", Hostname: "ep1b"},
{IP: "fd00:77:30::a", Hostname: "ip6svc1ex"},
{IP: "fd00:77:30::2:9ba6", Hostname: "ip6svc1in"},
},
Ports: []object.EndpointPort{
{Port: 80, Protocol: "tcp", Name: "http"},
},
},
},
Name: "svc1",
Namespace: "testns",
},
}
return eps
} }
func (APIConnReverseTest) GetNodeByName(name string) (*api.Node, error) { func (APIConnReverseTest) GetNodeByName(name string) (*api.Node, error) {
...@@ -178,6 +195,14 @@ func TestReverse(t *testing.T) { ...@@ -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"), 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() ctx := context.TODO()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment