dont match external services when endpoint is specified (#5734)

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2022-11-04 09:54:57 -04:00 committed by GitHub
parent ead84e1fa8
commit 47c99dc73b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View file

@ -384,6 +384,14 @@ var dnsTestCases = []kubeTestCase{
test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
},
}},
// A query for a subdomain of an external service should not resolve to the external service
{Case: test.Case{
Qname: "endpoint.external.testns.svc.cluster.local.", Qtype: dns.TypeCNAME,
Rcode: dns.RcodeNameError,
Ns: []dns.RR{
test.SOA("cluster.local. 5 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
},
}},
}
func TestServeDNS(t *testing.T) {

View file

@ -517,6 +517,10 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.
// External service
if svc.Type == api.ServiceTypeExternalName {
//External services cannot have endpoints, so skip this service if an endpoint is present in the request
if r.endpoint != "" {
continue
}
s := msg.Service{Key: strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/"), Host: svc.ExternalName, TTL: k.ttl}
if t, _ := s.HostType(); t == dns.TypeCNAME {
s.Key = strings.Join([]string{zonePath, Svc, svc.Namespace, svc.Name}, "/")