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
7c7772b7
Commit
7c7772b7
authored
May 05, 2020
by
Chris O'Haver
Committed by
GitHub
May 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
always add client metadata (#3874)
Signed-off-by:
Chris O'Haver
<
cohaver@infoblox.com
>
parent
9f9509b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
plugin/kubernetes/metadata.go
plugin/kubernetes/metadata.go
+14
-13
plugin/kubernetes/metadata_test.go
plugin/kubernetes/metadata_test.go
+18
-19
No files found.
plugin/kubernetes/metadata.go
View file @
7c7772b7
...
@@ -10,7 +10,21 @@ import (
...
@@ -10,7 +10,21 @@ import (
// Metadata implements the metadata.Provider interface.
// Metadata implements the metadata.Provider interface.
func
(
k
*
Kubernetes
)
Metadata
(
ctx
context
.
Context
,
state
request
.
Request
)
context
.
Context
{
func
(
k
*
Kubernetes
)
Metadata
(
ctx
context
.
Context
,
state
request
.
Request
)
context
.
Context
{
pod
:=
k
.
podWithIP
(
state
.
IP
())
if
pod
!=
nil
{
metadata
.
SetValueFunc
(
ctx
,
"kubernetes/client-namespace"
,
func
()
string
{
return
pod
.
Namespace
})
metadata
.
SetValueFunc
(
ctx
,
"kubernetes/client-pod-name"
,
func
()
string
{
return
pod
.
Name
})
}
zone
:=
plugin
.
Zones
(
k
.
Zones
)
.
Matches
(
state
.
Name
())
zone
:=
plugin
.
Zones
(
k
.
Zones
)
.
Matches
(
state
.
Name
())
if
zone
==
""
{
return
ctx
}
// possible optimization: cache r so it doesn't need to be calculated again in ServeDNS
// possible optimization: cache r so it doesn't need to be calculated again in ServeDNS
r
,
err
:=
parseRequest
(
state
.
Name
(),
zone
)
r
,
err
:=
parseRequest
(
state
.
Name
(),
zone
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -44,18 +58,5 @@ func (k *Kubernetes) Metadata(ctx context.Context, state request.Request) contex
...
@@ -44,18 +58,5 @@ func (k *Kubernetes) Metadata(ctx context.Context, state request.Request) contex
return
r
.
podOrSvc
return
r
.
podOrSvc
})
})
pod
:=
k
.
podWithIP
(
state
.
IP
())
if
pod
==
nil
{
return
ctx
}
metadata
.
SetValueFunc
(
ctx
,
"kubernetes/client-namespace"
,
func
()
string
{
return
pod
.
Namespace
})
metadata
.
SetValueFunc
(
ctx
,
"kubernetes/client-pod-name"
,
func
()
string
{
return
pod
.
Name
})
return
ctx
return
ctx
}
}
plugin/kubernetes/metadata_test.go
View file @
7c7772b7
...
@@ -26,23 +26,23 @@ var metadataCases = []struct {
...
@@ -26,23 +26,23 @@ var metadataCases = []struct {
{
{
Qname
:
"10-240-0-1.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"10-240-0-1.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Md
:
map
[
string
]
string
{
Md
:
map
[
string
]
string
{
"kubernetes/endpoint"
:
""
,
"kubernetes/endpoint"
:
""
,
"kubernetes/kind"
:
"pod"
,
"kubernetes/kind"
:
"pod"
,
"kubernetes/namespace"
:
"podns"
,
"kubernetes/namespace"
:
"podns"
,
"kubernetes/port-name"
:
"*"
,
"kubernetes/port-name"
:
"*"
,
"kubernetes/protocol"
:
"*"
,
"kubernetes/protocol"
:
"*"
,
"kubernetes/service"
:
"10-240-0-1"
,
"kubernetes/service"
:
"10-240-0-1"
,
},
},
},
},
{
{
Qname
:
"s.ns.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"s.ns.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Md
:
map
[
string
]
string
{
Md
:
map
[
string
]
string
{
"kubernetes/endpoint"
:
""
,
"kubernetes/endpoint"
:
""
,
"kubernetes/kind"
:
"svc"
,
"kubernetes/kind"
:
"svc"
,
"kubernetes/namespace"
:
"ns"
,
"kubernetes/namespace"
:
"ns"
,
"kubernetes/port-name"
:
"*"
,
"kubernetes/port-name"
:
"*"
,
"kubernetes/protocol"
:
"*"
,
"kubernetes/protocol"
:
"*"
,
"kubernetes/service"
:
"s"
,
"kubernetes/service"
:
"s"
,
},
},
},
},
{
{
...
@@ -81,6 +81,11 @@ var metadataCases = []struct {
...
@@ -81,6 +81,11 @@ var metadataCases = []struct {
"kubernetes/service"
:
"s"
,
"kubernetes/service"
:
"s"
,
},
},
},
},
{
Qname
:
"example.com."
,
Qtype
:
dns
.
TypeA
,
RemoteIP
:
"10.10.10.10"
,
Md
:
map
[
string
]
string
{},
},
}
}
func
mapsDiffer
(
a
,
b
map
[
string
]
string
)
bool
{
func
mapsDiffer
(
a
,
b
map
[
string
]
string
)
bool
{
...
@@ -128,7 +133,7 @@ func TestMetadataPodsVerified(t *testing.T) {
...
@@ -128,7 +133,7 @@ func TestMetadataPodsVerified(t *testing.T) {
ctx
:=
metadata
.
ContextWithMetadata
(
context
.
Background
())
ctx
:=
metadata
.
ContextWithMetadata
(
context
.
Background
())
state
:=
request
.
Request
{
state
:=
request
.
Request
{
Req
:
&
dns
.
Msg
{
Question
:
[]
dns
.
Question
{{
Name
:
"
s.ns.svc.cluster.local
."
,
Qtype
:
dns
.
TypeA
}}},
Req
:
&
dns
.
Msg
{
Question
:
[]
dns
.
Question
{{
Name
:
"
example.com
."
,
Qtype
:
dns
.
TypeA
}}},
Zone
:
"."
,
Zone
:
"."
,
W
:
&
test
.
ResponseWriter
{},
W
:
&
test
.
ResponseWriter
{},
}
}
...
@@ -136,12 +141,6 @@ func TestMetadataPodsVerified(t *testing.T) {
...
@@ -136,12 +141,6 @@ func TestMetadataPodsVerified(t *testing.T) {
k
.
Metadata
(
ctx
,
state
)
k
.
Metadata
(
ctx
,
state
)
expect
:=
map
[
string
]
string
{
expect
:=
map
[
string
]
string
{
"kubernetes/endpoint"
:
""
,
"kubernetes/kind"
:
"svc"
,
"kubernetes/namespace"
:
"ns"
,
"kubernetes/port-name"
:
"*"
,
"kubernetes/protocol"
:
"*"
,
"kubernetes/service"
:
"s"
,
"kubernetes/client-namespace"
:
"podns"
,
"kubernetes/client-namespace"
:
"podns"
,
"kubernetes/client-pod-name"
:
"foo"
,
"kubernetes/client-pod-name"
:
"foo"
,
}
}
...
...
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