Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
e6ef320d
Commit
e6ef320d
authored
Aug 27, 2018
by
Chris O'Haver
Committed by
Miek Gieben
Aug 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle blank name and namespaces (#2042)
parent
44447289
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
6 deletions
+33
-6
plugin/kubernetes/handler_pod_insecure_test.go
plugin/kubernetes/handler_pod_insecure_test.go
+1
-1
plugin/kubernetes/handler_test.go
plugin/kubernetes/handler_test.go
+7
-0
plugin/kubernetes/kubernetes.go
plugin/kubernetes/kubernetes.go
+21
-1
plugin/kubernetes/parse.go
plugin/kubernetes/parse.go
+4
-4
No files found.
plugin/kubernetes/handler_pod_insecure_test.go
View file @
e6ef320d
...
...
@@ -55,7 +55,7 @@ var podModeInsecureCases = []test.Case{
},
{
Qname
:
"podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
Rcode
NameError
,
Rcode
:
dns
.
Rcode
Success
,
Ns
:
[]
dns
.
RR
{
test
.
SOA
(
"cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1515173576 7200 1800 86400 30"
),
},
...
...
plugin/kubernetes/handler_test.go
View file @
e6ef320d
...
...
@@ -323,6 +323,13 @@ var dnsTestCases = []test.Case{
test
.
SOA
(
"cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"
),
},
},
{
Qname
:
"testns.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Ns
:
[]
dns
.
RR
{
test
.
SOA
(
"cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"
),
},
},
}
func
TestServeDNS
(
t
*
testing
.
T
)
{
...
...
plugin/kubernetes/kubernetes.go
View file @
e6ef320d
...
...
@@ -343,6 +343,16 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service,
zonePath
:=
msg
.
Path
(
zone
,
"coredns"
)
ip
:=
""
// handle empty pod name
if
podname
==
""
{
if
k
.
namespace
(
namespace
)
||
wildcard
(
namespace
)
{
// NODATA
return
nil
,
nil
}
// NXDOMAIN
return
nil
,
errNoItems
}
if
strings
.
Count
(
podname
,
"-"
)
==
3
&&
!
strings
.
Contains
(
podname
,
"--"
)
{
ip
=
strings
.
Replace
(
podname
,
"-"
,
"."
,
-
1
)
}
else
{
...
...
@@ -362,6 +372,7 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service,
return
[]
msg
.
Service
{{
Key
:
strings
.
Join
([]
string
{
zonePath
,
Pod
,
namespace
,
podname
},
"/"
),
Host
:
ip
,
TTL
:
k
.
ttl
}},
err
}
// PodModeVerified
err
=
errNoItems
if
wildcard
(
podname
)
&&
!
wildcard
(
namespace
)
{
// If namespace exist, err should be nil, so that we return nodata instead of NXDOMAIN
...
...
@@ -370,7 +381,6 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service,
}
}
// PodModeVerified
for
_
,
p
:=
range
k
.
APIConn
.
PodIndex
(
ip
)
{
// If namespace has a wildcard, filter results against Corefile namespace list.
if
wildcard
(
namespace
)
&&
!
k
.
namespaceExposed
(
p
.
Namespace
)
{
...
...
@@ -411,6 +421,16 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.
serviceList
[]
*
api
.
Service
)
// handle empty service name
if
r
.
service
==
""
{
if
k
.
namespace
(
r
.
namespace
)
||
wildcard
(
r
.
namespace
)
{
// NODATA
return
nil
,
nil
}
// NXDOMAIN
return
nil
,
errNoItems
}
if
wildcard
(
r
.
service
)
||
wildcard
(
r
.
namespace
)
{
serviceList
=
k
.
APIConn
.
ServiceList
()
endpointsListFunc
=
func
()
[]
*
api
.
Endpoints
{
return
k
.
APIConn
.
EndpointsList
()
}
...
...
plugin/kubernetes/parse.go
View file @
e6ef320d
...
...
@@ -43,10 +43,10 @@ func parseRequest(state request.Request) (r recordRequest, err error) {
r
.
port
=
"*"
r
.
protocol
=
"*"
r
.
service
=
"*"
r
.
namespace
=
"*"
//
r.endpoint is the odd one out, we need to know if it has been set or not. If it is
//
empty we should skip the endpoint check in k.get(). Hence we cannot set if to "*".
// for r.name, r.namespace and r.endpoint, we need to know if they have been set or not...
// For endpoint: if empty we should skip the endpoint check in k.get(). Hence we cannot set if to "*".
//
For name: myns.svc.cluster.local != *.myns.svc.cluster.local
//
For namespace: svc.cluster.local != *.svc.cluster.local
// start at the right and fill out recordRequest with the bits we find, so we look for
// pod|svc.namespace.service and then either
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment