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
b8e75509
Commit
b8e75509
authored
Feb 07, 2017
by
Miek Gieben
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:miekg/coredns
parents
fa0abe74
4b6860fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
30 deletions
+85
-30
middleware/kubernetes/handler.go
middleware/kubernetes/handler.go
+9
-5
middleware/kubernetes/kubernetes.go
middleware/kubernetes/kubernetes.go
+2
-2
middleware/proxy/google.go
middleware/proxy/google.go
+23
-19
middleware/proxy/upstream.go
middleware/proxy/upstream.go
+4
-4
test/kubernetes_test.go
test/kubernetes_test.go
+47
-0
No files found.
middleware/kubernetes/handler.go
View file @
b8e75509
...
@@ -26,11 +26,15 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
...
@@ -26,11 +26,15 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
// otherwise delegate to the next in the pipeline.
// otherwise delegate to the next in the pipeline.
zone
:=
middleware
.
Zones
(
k
.
Zones
)
.
Matches
(
state
.
Name
())
zone
:=
middleware
.
Zones
(
k
.
Zones
)
.
Matches
(
state
.
Name
())
if
zone
==
""
{
if
zone
==
""
{
// If this is a PTR request, and a the request is in a defined
if
state
.
Type
()
==
"PTR"
{
// pod/service cidr range, process the request in this middleware,
// If this is a PTR request, and a the request is in a defined
// otherwise pass to next middleware.
// pod/service cidr range, process the request in this middleware,
if
state
.
Type
()
!=
"PTR"
||
!
k
.
IsRequestInReverseRange
(
state
)
{
// otherwise pass to next middleware.
return
middleware
.
NextOrFailure
(
k
.
Name
(),
k
.
Next
,
ctx
,
w
,
r
)
if
!
k
.
IsRequestInReverseRange
(
state
)
{
return
middleware
.
NextOrFailure
(
k
.
Name
(),
k
.
Next
,
ctx
,
w
,
r
)
}
// Set the zone to this specific request.
zone
=
state
.
Name
()
}
}
}
}
...
...
middleware/kubernetes/kubernetes.go
View file @
b8e75509
...
@@ -508,7 +508,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
...
@@ -508,7 +508,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
return
nil
return
nil
}
}
for
_
,
service
:=
range
svcList
{
for
_
,
service
:=
range
svcList
{
if
!
dnsstrings
.
StringInSlice
(
service
.
Namespace
,
k
.
Namespaces
)
{
if
(
len
(
k
.
Namespaces
)
>
0
)
&&
!
dnsstrings
.
StringInSlice
(
service
.
Namespace
,
k
.
Namespaces
)
{
continue
continue
}
}
if
service
.
Spec
.
ClusterIP
==
ip
{
if
service
.
Spec
.
ClusterIP
==
ip
{
...
@@ -522,7 +522,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
...
@@ -522,7 +522,7 @@ func (k *Kubernetes) getServiceRecordForIP(ip, name string) []msg.Service {
return
nil
return
nil
}
}
for
_
,
ep
:=
range
epList
.
Items
{
for
_
,
ep
:=
range
epList
.
Items
{
if
!
dnsstrings
.
StringInSlice
(
ep
.
ObjectMeta
.
Namespace
,
k
.
Namespaces
)
{
if
(
len
(
k
.
Namespaces
)
>
0
)
&&
!
dnsstrings
.
StringInSlice
(
ep
.
ObjectMeta
.
Namespace
,
k
.
Namespaces
)
{
continue
continue
}
}
for
_
,
eps
:=
range
ep
.
Subsets
{
for
_
,
eps
:=
range
ep
.
Subsets
{
...
...
middleware/proxy/google.go
View file @
b8e75509
...
@@ -126,13 +126,7 @@ func (g *google) OnStartup(p *Proxy) error {
...
@@ -126,13 +126,7 @@ func (g *google) OnStartup(p *Proxy) error {
new
,
err
:=
g
.
bootstrapProxy
.
Lookup
(
state
,
g
.
endpoint
,
dns
.
TypeA
)
new
,
err
:=
g
.
bootstrapProxy
.
Lookup
(
state
,
g
.
endpoint
,
dns
.
TypeA
)
oldUpstream
:=
*
p
.
Upstreams
var
oldUpstream
Upstream
oldFrom
:=
""
var
oldEx
Exchanger
if
len
(
oldUpstream
)
>
0
{
oldFrom
=
oldUpstream
[
0
]
.
From
()
oldEx
=
oldUpstream
[
0
]
.
Exchanger
()
}
// ignore errors here, as we want to keep on trying.
// ignore errors here, as we want to keep on trying.
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -143,8 +137,13 @@ func (g *google) OnStartup(p *Proxy) error {
...
@@ -143,8 +137,13 @@ func (g *google) OnStartup(p *Proxy) error {
log
.
Printf
(
"[WARNING] Failed to bootstrap A records %q: %s"
,
g
.
endpoint
,
err
)
log
.
Printf
(
"[WARNING] Failed to bootstrap A records %q: %s"
,
g
.
endpoint
,
err
)
}
}
up
:=
newUpstream
(
addrs
,
oldFrom
,
oldEx
)
if
len
(
*
p
.
Upstreams
)
>
0
{
p
.
Upstreams
=
&
[]
Upstream
{
up
}
oldUpstream
=
(
*
p
.
Upstreams
)[
0
]
up
:=
newUpstream
(
addrs
,
oldUpstream
.
(
*
staticUpstream
))
p
.
Upstreams
=
&
[]
Upstream
{
up
}
}
else
{
log
.
Printf
(
"[WARNING] Failed to bootstrap upstreams %q"
,
g
.
endpoint
)
}
}
}
go
func
()
{
go
func
()
{
...
@@ -164,8 +163,11 @@ func (g *google) OnStartup(p *Proxy) error {
...
@@ -164,8 +163,11 @@ func (g *google) OnStartup(p *Proxy) error {
continue
continue
}
}
up
:=
newUpstream
(
addrs
,
oldFrom
,
oldEx
)
// TODO(miek): can this actually happen?
p
.
Upstreams
=
&
[]
Upstream
{
up
}
if
oldUpstream
!=
nil
{
up
:=
newUpstream
(
addrs
,
oldUpstream
.
(
*
staticUpstream
))
p
.
Upstreams
=
&
[]
Upstream
{
up
}
}
}
}
case
<-
g
.
quit
:
case
<-
g
.
quit
:
...
@@ -195,15 +197,17 @@ func extractAnswer(m *dns.Msg) ([]string, error) {
...
@@ -195,15 +197,17 @@ func extractAnswer(m *dns.Msg) ([]string, error) {
}
}
// newUpstream returns an upstream initialized with hosts.
// newUpstream returns an upstream initialized with hosts.
func
newUpstream
(
hosts
[]
string
,
from
string
,
ex
Exchanger
)
Upstream
{
func
newUpstream
(
hosts
[]
string
,
old
*
staticUpstream
)
Upstream
{
upstream
:=
&
staticUpstream
{
upstream
:=
&
staticUpstream
{
from
:
from
,
from
:
old
.
from
,
Hosts
:
nil
,
Hosts
:
nil
,
Policy
:
&
Random
{},
Policy
:
&
Random
{},
Spray
:
nil
,
Spray
:
nil
,
FailTimeout
:
10
*
time
.
Second
,
FailTimeout
:
10
*
time
.
Second
,
MaxFails
:
3
,
MaxFails
:
3
,
ex
:
ex
,
ex
:
old
.
ex
,
WithoutPathPrefix
:
old
.
WithoutPathPrefix
,
IgnoredSubDomains
:
old
.
IgnoredSubDomains
,
}
}
upstream
.
Hosts
=
make
([]
*
UpstreamHost
,
len
(
hosts
))
upstream
.
Hosts
=
make
([]
*
UpstreamHost
,
len
(
hosts
))
...
...
middleware/proxy/upstream.go
View file @
b8e75509
...
@@ -281,11 +281,11 @@ func (u *staticUpstream) Select() *UpstreamHost {
...
@@ -281,11 +281,11 @@ func (u *staticUpstream) Select() *UpstreamHost {
}
}
func
(
u
*
staticUpstream
)
IsAllowedDomain
(
name
string
)
bool
{
func
(
u
*
staticUpstream
)
IsAllowedDomain
(
name
string
)
bool
{
for
_
,
ignoredSubDomain
:=
range
u
.
IgnoredSubDomains
{
if
dns
.
Name
(
name
)
==
dns
.
Name
(
u
.
From
())
{
if
dns
.
Name
(
name
)
==
dns
.
Name
(
u
.
From
())
{
return
true
return
true
}
}
for
_
,
ignoredSubDomain
:=
range
u
.
IgnoredSubDomains
{
if
middleware
.
Name
(
ignoredSubDomain
)
.
Matches
(
name
)
{
if
middleware
.
Name
(
ignoredSubDomain
)
.
Matches
(
name
)
{
return
false
return
false
}
}
...
...
test/kubernetes_test.go
View file @
b8e75509
...
@@ -315,6 +315,42 @@ var dnsTestCasesPartialCidrReverseZone = []test.Case{
...
@@ -315,6 +315,42 @@ var dnsTestCasesPartialCidrReverseZone = []test.Case{
},
},
}
}
var
dnsTestCasesAllNSExposed
=
[]
test
.
Case
{
{
Qname
:
"svc-1-a.test-1.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"
),
},
},
{
Qname
:
"svc-c.test-2.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.120"
),
},
},
{
Qname
:
"123.0.0.10.in-addr.arpa."
,
Qtype
:
dns
.
TypePTR
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{},
},
{
Qname
:
"100.0.0.10.in-addr.arpa."
,
Qtype
:
dns
.
TypePTR
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
PTR
(
"100.0.0.10.in-addr.arpa. 303 IN PTR svc-1-a.test-1.svc.cluster.local."
),
},
},
{
Qname
:
"120.0.0.10.in-addr.arpa."
,
Qtype
:
dns
.
TypePTR
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
PTR
(
"120.0.0.10.in-addr.arpa. 303 IN PTR svc-c.test-2.svc.cluster.local."
),
},
},
}
func
createTestServer
(
t
*
testing
.
T
,
corefile
string
)
(
*
caddy
.
Instance
,
string
)
{
func
createTestServer
(
t
*
testing
.
T
,
corefile
string
)
(
*
caddy
.
Instance
,
string
)
{
server
,
err
:=
CoreDNSServer
(
corefile
)
server
,
err
:=
CoreDNSServer
(
corefile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -424,3 +460,14 @@ func TestKubernetesIntegrationPartialCidrReverseZone(t *testing.T) {
...
@@ -424,3 +460,14 @@ func TestKubernetesIntegrationPartialCidrReverseZone(t *testing.T) {
`
`
doIntegrationTests
(
t
,
corefile
,
dnsTestCasesPartialCidrReverseZone
)
doIntegrationTests
(
t
,
corefile
,
dnsTestCasesPartialCidrReverseZone
)
}
}
func
TestKubernetesIntegrationAllNSExposed
(
t
*
testing
.
T
)
{
corefile
:=
`.:0 {
kubernetes cluster.local {
endpoint http://localhost:8080
cidrs 10.0.0.0/24
}
`
doIntegrationTests
(
t
,
corefile
,
dnsTestCasesAllNSExposed
)
}
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