mirror of
https://github.com/coredns/coredns.git
synced 2025-10-31 18:23:13 -04:00
mw/kubernetes: remove zone from parseRequest (#938)
* mw/kubernetes: remove zone from parseRequest State has the zone info as well, so don't need to have it in parseRequest anymore. * Fix up tests * improve test coverage
This commit is contained in:
@@ -315,7 +315,7 @@ func (k *Kubernetes) Entries(state request.Request) ([]msg.Service, error) {
|
|||||||
return nil, errNoItems
|
return nil, errNoItems
|
||||||
}
|
}
|
||||||
|
|
||||||
records := k.getRecordsForK8sItems(services, pods, r)
|
records := k.getRecordsForK8sItems(services, pods, state.Zone)
|
||||||
return records, nil
|
return records, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,8 +332,8 @@ func endpointHostname(addr api.EndpointAddress) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Kubernetes) getRecordsForK8sItems(services []kService, pods []kPod, r recordRequest) (records []msg.Service) {
|
func (k *Kubernetes) getRecordsForK8sItems(services []kService, pods []kPod, zone string) (records []msg.Service) {
|
||||||
zonePath := msg.Path(r.zone, "coredns")
|
zonePath := msg.Path(zone, "coredns")
|
||||||
|
|
||||||
for _, svc := range services {
|
for _, svc := range services {
|
||||||
if svc.addr == api.ClusterIPNone || len(svc.endpoints) > 0 {
|
if svc.addr == api.ClusterIPNone || len(svc.endpoints) > 0 {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ type recordRequest struct {
|
|||||||
// A each name can be for a pod or a service, here we track what we've seen. This value is true for
|
// A each name can be for a pod or a service, here we track what we've seen. This value is true for
|
||||||
// pods and false for services. If we ever need to extend this well use a typed value.
|
// pods and false for services. If we ever need to extend this well use a typed value.
|
||||||
podOrSvc string
|
podOrSvc string
|
||||||
zone string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseRequest parses the qname to find all the elements we need for querying k8s.
|
// parseRequest parses the qname to find all the elements we need for querying k8s.
|
||||||
@@ -34,8 +33,6 @@ func (k *Kubernetes) parseRequest(state request.Request) (r recordRequest, err e
|
|||||||
base, _ := dnsutil.TrimZone(state.Name(), state.Zone)
|
base, _ := dnsutil.TrimZone(state.Name(), state.Zone)
|
||||||
segs := dns.SplitDomainName(base)
|
segs := dns.SplitDomainName(base)
|
||||||
|
|
||||||
r.zone = state.Zone
|
|
||||||
|
|
||||||
offset := 0
|
offset := 0
|
||||||
if state.QType() == dns.TypeSRV {
|
if state.QType() == dns.TypeSRV {
|
||||||
// The kubernetes peer-finder expects queries with empty port and service to resolve
|
// The kubernetes peer-finder expects queries with empty port and service to resolve
|
||||||
@@ -101,6 +98,5 @@ func (r recordRequest) String() string {
|
|||||||
s += "." + r.service
|
s += "." + r.service
|
||||||
s += "." + r.namespace
|
s += "." + r.namespace
|
||||||
s += "." + r.podOrSvc
|
s += "." + r.podOrSvc
|
||||||
s += "." + r.zone
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,17 +19,23 @@ func TestParseRequest(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// valid SRV request
|
// valid SRV request
|
||||||
"_http._tcp.webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV,
|
"_http._tcp.webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV,
|
||||||
"http.tcp..webs.mynamespace.svc.intern.webs.tests.",
|
"http.tcp..webs.mynamespace.svc",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// wildcard acceptance
|
// wildcard acceptance
|
||||||
"*.any.*.any.svc.inter.webs.test.", dns.TypeSRV,
|
"*.any.*.any.svc.inter.webs.test.", dns.TypeSRV,
|
||||||
"*.any..*.any.svc.intern.webs.tests.",
|
"*.any..*.any.svc",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// A request of endpoint
|
// A request of endpoint
|
||||||
"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", dns.TypeA,
|
"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", dns.TypeA,
|
||||||
"..1-2-3-4.webs.mynamespace.svc.intern.webs.tests.",
|
"..1-2-3-4.webs.mynamespace.svc",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
|
||||||
|
// 3 segments
|
||||||
|
"webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV,
|
||||||
|
"*...webs.mynamespace.svc",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user