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
9719a47c
Commit
9719a47c
authored
Feb 16, 2018
by
Chris O'Haver
Committed by
John Belamaric
Feb 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/kubernetes: Add noendpoints option (#1536)
* add noendpoints option * go fmt
parent
2cad04ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
15 deletions
+96
-15
plugin/kubernetes/README.md
plugin/kubernetes/README.md
+2
-0
plugin/kubernetes/controller.go
plugin/kubernetes/controller.go
+24
-13
plugin/kubernetes/setup.go
plugin/kubernetes/setup.go
+7
-1
plugin/kubernetes/setup_test.go
plugin/kubernetes/setup_test.go
+63
-1
No files found.
plugin/kubernetes/README.md
View file @
9719a47c
...
@@ -86,6 +86,8 @@ kubernetes [ZONES...] {
...
@@ -86,6 +86,8 @@ kubernetes [ZONES...] {
to a file structured like resolv.conf.
to a file structured like resolv.conf.
*
`ttl`
allows you to set a custom TTL for responses. The default (and allowed minimum) is to use
*
`ttl`
allows you to set a custom TTL for responses. The default (and allowed minimum) is to use
5 seconds, the maximum is capped at 3600 seconds.
5 seconds, the maximum is capped at 3600 seconds.
*
`noendpoints`
will turn off the serving of endpoint records by disabling the watch on endpoints.
All endpoint queries and headless service queries will result in an NXDOMAIN.
*
`fallthrough`
**[ZONES...]**
If a query for a record in the zones for which the plugin is authoritative
*
`fallthrough`
**[ZONES...]**
If a query for a record in the zones for which the plugin is authoritative
results in NXDOMAIN, normally that is what the response will be. However, if you specify this option,
results in NXDOMAIN, normally that is what the response will be. However, if you specify this option,
the query will instead be passed on down the plugin chain, which can include another plugin to handle
the query will instead be passed on down the plugin chain, which can include another plugin to handle
...
...
plugin/kubernetes/controller.go
View file @
9719a47c
...
@@ -76,8 +76,9 @@ type dnsControl struct {
...
@@ -76,8 +76,9 @@ type dnsControl struct {
}
}
type
dnsControlOpts
struct
{
type
dnsControlOpts
struct
{
initPodCache
bool
initPodCache
bool
resyncPeriod
time
.
Duration
initEndpointsCache
bool
resyncPeriod
time
.
Duration
// Label handling.
// Label handling.
labelSelector
*
meta
.
LabelSelector
labelSelector
*
meta
.
LabelSelector
selector
labels
.
Selector
selector
labels
.
Selector
...
@@ -113,15 +114,17 @@ func newdnsController(kubeClient *kubernetes.Clientset, opts dnsControlOpts) *dn
...
@@ -113,15 +114,17 @@ func newdnsController(kubeClient *kubernetes.Clientset, opts dnsControlOpts) *dn
cache
.
Indexers
{
podIPIndex
:
podIPIndexFunc
})
cache
.
Indexers
{
podIPIndex
:
podIPIndexFunc
})
}
}
dns
.
epLister
,
dns
.
epController
=
cache
.
NewIndexerInformer
(
if
opts
.
initEndpointsCache
{
&
cache
.
ListWatch
{
dns
.
epLister
,
dns
.
epController
=
cache
.
NewIndexerInformer
(
ListFunc
:
endpointsListFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
&
cache
.
ListWatch
{
WatchFunc
:
endpointsWatchFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
ListFunc
:
endpointsListFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
},
WatchFunc
:
endpointsWatchFunc
(
dns
.
client
,
namespace
,
dns
.
selector
),
&
api
.
Endpoints
{},
},
opts
.
resyncPeriod
,
&
api
.
Endpoints
{},
cache
.
ResourceEventHandlerFuncs
{
AddFunc
:
dns
.
Add
,
UpdateFunc
:
dns
.
Update
,
DeleteFunc
:
dns
.
Delete
},
opts
.
resyncPeriod
,
cache
.
Indexers
{
epNameNamespaceIndex
:
epNameNamespaceIndexFunc
,
epIPIndex
:
epIPIndexFunc
})
cache
.
ResourceEventHandlerFuncs
{
AddFunc
:
dns
.
Add
,
UpdateFunc
:
dns
.
Update
,
DeleteFunc
:
dns
.
Delete
},
cache
.
Indexers
{
epNameNamespaceIndex
:
epNameNamespaceIndexFunc
,
epIPIndex
:
epIPIndexFunc
})
}
dns
.
nsLister
.
Store
,
dns
.
nsController
=
cache
.
NewInformer
(
dns
.
nsLister
.
Store
,
dns
.
nsController
=
cache
.
NewInformer
(
&
cache
.
ListWatch
{
&
cache
.
ListWatch
{
...
@@ -307,7 +310,9 @@ func (dns *dnsControl) Stop() error {
...
@@ -307,7 +310,9 @@ func (dns *dnsControl) Stop() error {
// Run starts the controller.
// Run starts the controller.
func
(
dns
*
dnsControl
)
Run
()
{
func
(
dns
*
dnsControl
)
Run
()
{
go
dns
.
svcController
.
Run
(
dns
.
stopCh
)
go
dns
.
svcController
.
Run
(
dns
.
stopCh
)
go
dns
.
epController
.
Run
(
dns
.
stopCh
)
if
dns
.
epController
!=
nil
{
go
dns
.
epController
.
Run
(
dns
.
stopCh
)
}
if
dns
.
podController
!=
nil
{
if
dns
.
podController
!=
nil
{
go
dns
.
podController
.
Run
(
dns
.
stopCh
)
go
dns
.
podController
.
Run
(
dns
.
stopCh
)
}
}
...
@@ -318,7 +323,10 @@ func (dns *dnsControl) Run() {
...
@@ -318,7 +323,10 @@ func (dns *dnsControl) Run() {
// HasSynced calls on all controllers.
// HasSynced calls on all controllers.
func
(
dns
*
dnsControl
)
HasSynced
()
bool
{
func
(
dns
*
dnsControl
)
HasSynced
()
bool
{
a
:=
dns
.
svcController
.
HasSynced
()
a
:=
dns
.
svcController
.
HasSynced
()
b
:=
dns
.
epController
.
HasSynced
()
b
:=
true
if
dns
.
epController
!=
nil
{
b
=
dns
.
epController
.
HasSynced
()
}
c
:=
true
c
:=
true
if
dns
.
podController
!=
nil
{
if
dns
.
podController
!=
nil
{
c
=
dns
.
podController
.
HasSynced
()
c
=
dns
.
podController
.
HasSynced
()
...
@@ -431,6 +439,9 @@ func (dns *dnsControl) EpIndexReverse(ip string) (ep []*api.Endpoints) {
...
@@ -431,6 +439,9 @@ func (dns *dnsControl) EpIndexReverse(ip string) (ep []*api.Endpoints) {
}
}
func
(
dns
*
dnsControl
)
EndpointsList
()
(
eps
[]
*
api
.
Endpoints
)
{
func
(
dns
*
dnsControl
)
EndpointsList
()
(
eps
[]
*
api
.
Endpoints
)
{
if
dns
.
epLister
==
nil
{
return
nil
}
os
:=
dns
.
epLister
.
List
()
os
:=
dns
.
epLister
.
List
()
for
_
,
o
:=
range
os
{
for
_
,
o
:=
range
os
{
ep
,
ok
:=
o
.
(
*
api
.
Endpoints
)
ep
,
ok
:=
o
.
(
*
api
.
Endpoints
)
...
...
plugin/kubernetes/setup.go
View file @
9719a47c
...
@@ -92,7 +92,8 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
...
@@ -92,7 +92,8 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
k8s
.
autoPathSearch
=
searchFromResolvConf
()
k8s
.
autoPathSearch
=
searchFromResolvConf
()
opts
:=
dnsControlOpts
{
opts
:=
dnsControlOpts
{
resyncPeriod
:
defaultResyncPeriod
,
initEndpointsCache
:
true
,
resyncPeriod
:
defaultResyncPeriod
,
}
}
k8s
.
opts
=
opts
k8s
.
opts
=
opts
...
@@ -221,6 +222,11 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
...
@@ -221,6 +222,11 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
return
nil
,
c
.
Errf
(
"transfer from is not supported with this plugin"
)
return
nil
,
c
.
Errf
(
"transfer from is not supported with this plugin"
)
}
}
k8s
.
TransferTo
=
tos
k8s
.
TransferTo
=
tos
case
"noendpoints"
:
if
len
(
c
.
RemainingArgs
())
!=
0
{
return
nil
,
c
.
ArgErr
()
}
k8s
.
opts
.
initEndpointsCache
=
false
default
:
default
:
return
nil
,
c
.
Errf
(
"unknown property '%s'"
,
c
.
Val
())
return
nil
,
c
.
Errf
(
"unknown property '%s'"
,
c
.
Val
())
}
}
...
...
plugin/kubernetes/setup_test.go
View file @
9719a47c
...
@@ -491,7 +491,7 @@ kubernetes cluster.local`,
...
@@ -491,7 +491,7 @@ kubernetes cluster.local`,
}
}
}
}
func
TestKubernetes
EndpointsParse
(
t
*
testing
.
T
)
{
func
TestKubernetes
ParseEndpointPodNames
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
input
string
// Corefile data as string
input
string
// Corefile data as string
shouldErr
bool
// true if test case is exected to produce an error.
shouldErr
bool
// true if test case is exected to produce an error.
...
@@ -553,3 +553,65 @@ func TestKubernetesEndpointsParse(t *testing.T) {
...
@@ -553,3 +553,65 @@ func TestKubernetesEndpointsParse(t *testing.T) {
}
}
}
}
}
}
func
TestKubernetesParseNoEndpoints
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
string
// Corefile data as string
shouldErr
bool
// true if test case is exected to produce an error.
expectedErrContent
string
// substring from the expected error. Empty for positive cases.
expectedEndpointsInit
bool
}{
// valid
{
`kubernetes coredns.local {
noendpoints
}`
,
false
,
""
,
false
,
},
// invalid
{
`kubernetes coredns.local {
noendpoints ixnay on the endpointsay
}`
,
true
,
"rong argument count or unexpected"
,
true
,
},
// not set
{
`kubernetes coredns.local {
}`
,
false
,
""
,
true
,
},
}
for
i
,
test
:=
range
tests
{
c
:=
caddy
.
NewTestController
(
"dns"
,
test
.
input
)
k8sController
,
err
:=
kubernetesParse
(
c
)
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %d: Expected error, but did not find error for input '%s'. Error was: '%v'"
,
i
,
test
.
input
,
err
)
}
if
err
!=
nil
{
if
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d: Expected no error but found one for input %s. Error was: %v"
,
i
,
test
.
input
,
err
)
continue
}
if
!
strings
.
Contains
(
err
.
Error
(),
test
.
expectedErrContent
)
{
t
.
Errorf
(
"Test %d: Expected error to contain: %v, found error: %v, input: %s"
,
i
,
test
.
expectedErrContent
,
err
,
test
.
input
)
}
continue
}
foundEndpointsInit
:=
k8sController
.
opts
.
initEndpointsCache
if
foundEndpointsInit
!=
test
.
expectedEndpointsInit
{
t
.
Errorf
(
"Test %d: Expected kubernetes controller to be initialized with endpoints watch '%v'. Instead found endpoints watch '%v' for input '%s'"
,
i
,
test
.
expectedEndpointsInit
,
foundEndpointsInit
,
test
.
input
)
}
}
}
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