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
2e3ef777
Commit
2e3ef777
authored
May 29, 2020
by
Michael Kashin
Committed by
GitHub
May 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
k8s_external can now resolve CNAME returned by AWS ELB/NLB (#3916)
Automatically submitted.
parent
54fb2112
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
17 deletions
+72
-17
plugin/k8s_external/external.go
plugin/k8s_external/external.go
+5
-2
plugin/k8s_external/external_test.go
plugin/k8s_external/external_test.go
+41
-10
plugin/k8s_external/msg_to_dns.go
plugin/k8s_external/msg_to_dns.go
+17
-4
plugin/k8s_external/setup.go
plugin/k8s_external/setup.go
+3
-0
plugin/kubernetes/object/service.go
plugin/kubernetes/object/service.go
+6
-1
No files found.
plugin/k8s_external/external.go
View file @
2e3ef777
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
"github.com/miekg/dns"
...
@@ -39,6 +40,8 @@ type External struct {
...
@@ -39,6 +40,8 @@ type External struct {
apex
string
apex
string
ttl
uint32
ttl
uint32
upstream
*
upstream
.
Upstream
externalFunc
func
(
request
.
Request
)
([]
msg
.
Service
,
int
)
externalFunc
func
(
request
.
Request
)
([]
msg
.
Service
,
int
)
externalAddrFunc
func
(
request
.
Request
)
[]
dns
.
RR
externalAddrFunc
func
(
request
.
Request
)
[]
dns
.
RR
}
}
...
@@ -90,9 +93,9 @@ func (e *External) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
...
@@ -90,9 +93,9 @@ func (e *External) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
switch
state
.
QType
()
{
switch
state
.
QType
()
{
case
dns
.
TypeA
:
case
dns
.
TypeA
:
m
.
Answer
=
e
.
a
(
svc
,
state
)
m
.
Answer
=
e
.
a
(
ctx
,
svc
,
state
)
case
dns
.
TypeAAAA
:
case
dns
.
TypeAAAA
:
m
.
Answer
=
e
.
aaaa
(
svc
,
state
)
m
.
Answer
=
e
.
aaaa
(
ctx
,
svc
,
state
)
case
dns
.
TypeSRV
:
case
dns
.
TypeSRV
:
m
.
Answer
,
m
.
Extra
=
e
.
srv
(
svc
,
state
)
m
.
Answer
,
m
.
Extra
=
e
.
srv
(
svc
,
state
)
default
:
default
:
...
...
plugin/k8s_external/external_test.go
View file @
2e3ef777
...
@@ -41,6 +41,7 @@ func TestExternal(t *testing.T) {
...
@@ -41,6 +41,7 @@ func TestExternal(t *testing.T) {
}
}
resp
:=
w
.
Msg
resp
:=
w
.
Msg
if
resp
==
nil
{
if
resp
==
nil
{
t
.
Fatalf
(
"Test %d, got nil message and no error for %q"
,
i
,
r
.
Question
[
0
]
.
Name
)
t
.
Fatalf
(
"Test %d, got nil message and no error for %q"
,
i
,
r
.
Question
[
0
]
.
Name
)
}
}
...
@@ -147,21 +148,33 @@ var tests = []test.Case{
...
@@ -147,21 +148,33 @@ var tests = []test.Case{
test
.
SOA
(
"example.com. 5 IN SOA ns1.dns.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"
),
test
.
SOA
(
"example.com. 5 IN SOA ns1.dns.example.com. hostmaster.example.com. 1499347823 7200 1800 86400 5"
),
},
},
},
},
{
Qname
:
"svc11.testns.example.com."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"svc11.testns.example.com. 5 IN A 1.2.3.4"
),
},
},
{
Qname
:
"svc12.testns.example.com."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
CNAME
(
"svc12.testns.example.com. 5 IN CNAME dummy.hostname"
),
},
},
}
}
type
external
struct
{}
type
external
struct
{}
func
(
external
)
HasSynced
()
bool
{
return
true
}
func
(
external
)
HasSynced
()
bool
{
return
true
}
func
(
external
)
Run
()
{}
func
(
external
)
Run
()
{}
func
(
external
)
Stop
()
error
{
return
nil
}
func
(
external
)
Stop
()
error
{
return
nil
}
func
(
external
)
EpIndexReverse
(
string
)
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
EpIndexReverse
(
string
)
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
SvcIndexReverse
(
string
)
[]
*
object
.
Service
{
return
nil
}
func
(
external
)
SvcIndexReverse
(
string
)
[]
*
object
.
Service
{
return
nil
}
func
(
external
)
Modified
()
int64
{
return
0
}
func
(
external
)
Modified
()
int64
{
return
0
}
func
(
external
)
EpIndex
(
s
string
)
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
EpIndex
(
s
string
)
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
EndpointsList
()
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
EndpointsList
()
[]
*
object
.
Endpoints
{
return
nil
}
func
(
external
)
GetNodeByName
(
ctx
context
.
Context
,
name
string
)
(
*
api
.
Node
,
error
)
{
return
nil
,
nil
}
func
(
external
)
GetNodeByName
(
ctx
context
.
Context
,
name
string
)
(
*
api
.
Node
,
error
)
{
return
nil
,
nil
}
func
(
external
)
SvcIndex
(
s
string
)
[]
*
object
.
Service
{
return
svcIndexExternal
[
s
]
}
func
(
external
)
SvcIndex
(
s
string
)
[]
*
object
.
Service
{
return
svcIndexExternal
[
s
]
}
func
(
external
)
PodIndex
(
string
)
[]
*
object
.
Pod
{
return
nil
}
func
(
external
)
PodIndex
(
string
)
[]
*
object
.
Pod
{
return
nil
}
func
(
external
)
GetNamespaceByName
(
name
string
)
(
*
api
.
Namespace
,
error
)
{
func
(
external
)
GetNamespaceByName
(
name
string
)
(
*
api
.
Namespace
,
error
)
{
return
&
api
.
Namespace
{
return
&
api
.
Namespace
{
...
@@ -192,6 +205,24 @@ var svcIndexExternal = map[string][]*object.Service{
...
@@ -192,6 +205,24 @@ var svcIndexExternal = map[string][]*object.Service{
Ports
:
[]
api
.
ServicePort
{{
Name
:
"http"
,
Protocol
:
"tcp"
,
Port
:
80
}},
Ports
:
[]
api
.
ServicePort
{{
Name
:
"http"
,
Protocol
:
"tcp"
,
Port
:
80
}},
},
},
},
},
"svc11.testns"
:
{
{
Name
:
"svc11"
,
Namespace
:
"testns"
,
Type
:
api
.
ServiceTypeLoadBalancer
,
ExternalIPs
:
[]
string
{
"1.2.3.4"
},
Ports
:
[]
api
.
ServicePort
{{
Name
:
"http"
,
Protocol
:
"tcp"
,
Port
:
80
}},
},
},
"svc12.testns"
:
{
{
Name
:
"svc12"
,
Namespace
:
"testns"
,
Type
:
api
.
ServiceTypeLoadBalancer
,
ExternalIPs
:
[]
string
{
"dummy.hostname"
},
Ports
:
[]
api
.
ServicePort
{{
Name
:
"http"
,
Protocol
:
"tcp"
,
Port
:
80
}},
},
},
}
}
func
(
external
)
ServiceList
()
[]
*
object
.
Service
{
func
(
external
)
ServiceList
()
[]
*
object
.
Service
{
...
...
plugin/k8s_external/msg_to_dns.go
View file @
2e3ef777
package
external
package
external
import
(
import
(
"context"
"math"
"math"
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/etcd/msg"
...
@@ -9,7 +10,7 @@ import (
...
@@ -9,7 +10,7 @@ import (
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
func
(
e
*
External
)
a
(
services
[]
msg
.
Service
,
state
request
.
Request
)
(
records
[]
dns
.
RR
)
{
func
(
e
*
External
)
a
(
ctx
context
.
Context
,
services
[]
msg
.
Service
,
state
request
.
Request
)
(
records
[]
dns
.
RR
)
{
dup
:=
make
(
map
[
string
]
struct
{})
dup
:=
make
(
map
[
string
]
struct
{})
for
_
,
s
:=
range
services
{
for
_
,
s
:=
range
services
{
...
@@ -18,7 +19,13 @@ func (e *External) a(services []msg.Service, state request.Request) (records []d
...
@@ -18,7 +19,13 @@ func (e *External) a(services []msg.Service, state request.Request) (records []d
switch
what
{
switch
what
{
case
dns
.
TypeCNAME
:
case
dns
.
TypeCNAME
:
// can't happen
rr
:=
s
.
NewCNAME
(
state
.
QName
(),
s
.
Host
)
records
=
append
(
records
,
rr
)
if
resp
,
err
:=
e
.
upstream
.
Lookup
(
ctx
,
state
,
dns
.
Fqdn
(
s
.
Host
),
dns
.
TypeA
);
err
==
nil
{
for
_
,
rr
:=
range
resp
.
Answer
{
records
=
append
(
records
,
rr
)
}
}
case
dns
.
TypeA
:
case
dns
.
TypeA
:
if
_
,
ok
:=
dup
[
s
.
Host
];
!
ok
{
if
_
,
ok
:=
dup
[
s
.
Host
];
!
ok
{
...
@@ -35,7 +42,7 @@ func (e *External) a(services []msg.Service, state request.Request) (records []d
...
@@ -35,7 +42,7 @@ func (e *External) a(services []msg.Service, state request.Request) (records []d
return
records
return
records
}
}
func
(
e
*
External
)
aaaa
(
services
[]
msg
.
Service
,
state
request
.
Request
)
(
records
[]
dns
.
RR
)
{
func
(
e
*
External
)
aaaa
(
ctx
context
.
Context
,
services
[]
msg
.
Service
,
state
request
.
Request
)
(
records
[]
dns
.
RR
)
{
dup
:=
make
(
map
[
string
]
struct
{})
dup
:=
make
(
map
[
string
]
struct
{})
for
_
,
s
:=
range
services
{
for
_
,
s
:=
range
services
{
...
@@ -44,7 +51,13 @@ func (e *External) aaaa(services []msg.Service, state request.Request) (records
...
@@ -44,7 +51,13 @@ func (e *External) aaaa(services []msg.Service, state request.Request) (records
switch
what
{
switch
what
{
case
dns
.
TypeCNAME
:
case
dns
.
TypeCNAME
:
// can't happen
rr
:=
s
.
NewCNAME
(
state
.
QName
(),
s
.
Host
)
records
=
append
(
records
,
rr
)
if
resp
,
err
:=
e
.
upstream
.
Lookup
(
ctx
,
state
,
dns
.
Fqdn
(
s
.
Host
),
dns
.
TypeAAAA
);
err
==
nil
{
for
_
,
rr
:=
range
resp
.
Answer
{
records
=
append
(
records
,
rr
)
}
}
case
dns
.
TypeA
:
case
dns
.
TypeA
:
// nada
// nada
...
...
plugin/k8s_external/setup.go
View file @
2e3ef777
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy"
)
)
...
@@ -30,6 +31,8 @@ func setup(c *caddy.Controller) error {
...
@@ -30,6 +31,8 @@ func setup(c *caddy.Controller) error {
return
nil
return
nil
})
})
e
.
upstream
=
upstream
.
New
()
dnsserver
.
GetConfig
(
c
)
.
AddPlugin
(
func
(
next
plugin
.
Handler
)
plugin
.
Handler
{
dnsserver
.
GetConfig
(
c
)
.
AddPlugin
(
func
(
next
plugin
.
Handler
)
plugin
.
Handler
{
e
.
Next
=
next
e
.
Next
=
next
return
e
return
e
...
...
plugin/kubernetes/object/service.go
View file @
2e3ef777
...
@@ -62,7 +62,12 @@ func toService(skipCleanup bool, svc *api.Service) *Service {
...
@@ -62,7 +62,12 @@ func toService(skipCleanup bool, svc *api.Service) *Service {
li
:=
copy
(
s
.
ExternalIPs
,
svc
.
Spec
.
ExternalIPs
)
li
:=
copy
(
s
.
ExternalIPs
,
svc
.
Spec
.
ExternalIPs
)
for
i
,
lb
:=
range
svc
.
Status
.
LoadBalancer
.
Ingress
{
for
i
,
lb
:=
range
svc
.
Status
.
LoadBalancer
.
Ingress
{
s
.
ExternalIPs
[
li
+
i
]
=
lb
.
IP
if
lb
.
IP
!=
""
{
s
.
ExternalIPs
[
li
+
i
]
=
lb
.
IP
continue
}
s
.
ExternalIPs
[
li
+
i
]
=
lb
.
Hostname
}
}
if
!
skipCleanup
{
if
!
skipCleanup
{
...
...
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