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
e2238cfa
Commit
e2238cfa
authored
Mar 30, 2020
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add _grpc_config replies
Signed-off-by:
Miek Gieben
<
miek@miek.nl
>
parent
36dec4ca
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
5 deletions
+33
-5
plugin/traffic/lb.go
plugin/traffic/lb.go
+14
-0
plugin/traffic/setup.go
plugin/traffic/setup.go
+4
-0
plugin/traffic/setup_test.go
plugin/traffic/setup_test.go
+11
-0
plugin/traffic/traffic.go
plugin/traffic/traffic.go
+3
-4
plugin/traffic/traffic_test.go
plugin/traffic/traffic_test.go
+1
-1
No files found.
plugin/traffic/lb.go
0 → 100644
View file @
e2238cfa
package
traffic
import
"github.com/miekg/dns"
// See https://github.com/grpc/grpc/blob/master/doc/service_config.md for the fields in this proto.
// We encode it as json and return it in a TXT field.
var
lbTXT
=
`grpc_config=[{"serviceConfig":{"loadBalancingConfig":[{"xds_experimental":{"lrs_load_reporting_server_name":""}}]}}]`
func
txt
(
z
string
)
[]
dns
.
RR
{
return
[]
dns
.
RR
{
&
dns
.
TXT
{
Hdr
:
dns
.
RR_Header
{
Name
:
z
,
Rrtype
:
dns
.
TypeTXT
,
Class
:
dns
.
ClassINET
,
Ttl
:
5
},
Txt
:
[]
string
{
lbTXT
},
}}
}
plugin/traffic/setup.go
View file @
e2238cfa
...
@@ -2,6 +2,7 @@ package traffic
...
@@ -2,6 +2,7 @@ package traffic
import
(
import
(
"crypto/tls"
"crypto/tls"
"encoding/json"
"fmt"
"fmt"
"math/rand"
"math/rand"
"strings"
"strings"
...
@@ -31,6 +32,9 @@ func setup(c *caddy.Controller) error {
...
@@ -31,6 +32,9 @@ func setup(c *caddy.Controller) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
plugin
.
Error
(
"traffic"
,
err
)
return
plugin
.
Error
(
"traffic"
,
err
)
}
}
if
_
,
err
:=
json
.
Marshal
(
lbTXT
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to marshal grpc serverConfig: %s"
,
err
)
}
dnsserver
.
GetConfig
(
c
)
.
AddPlugin
(
func
(
next
plugin
.
Handler
)
plugin
.
Handler
{
dnsserver
.
GetConfig
(
c
)
.
AddPlugin
(
func
(
next
plugin
.
Handler
)
plugin
.
Handler
{
t
.
Next
=
next
t
.
Next
=
next
...
...
plugin/traffic/setup_test.go
View file @
e2238cfa
package
traffic
package
traffic
import
(
import
(
"encoding/json"
"testing"
"testing"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy"
...
@@ -13,6 +14,16 @@ func TestSetup(t *testing.T) {
...
@@ -13,6 +14,16 @@ func TestSetup(t *testing.T) {
}
}
}
}
func
TestLBTxt
(
t
*
testing
.
T
)
{
_
,
err
:=
json
.
Marshal
(
lbTXT
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to marshal grpc serverConfig: %s"
,
err
)
}
if
len
(
lbTXT
)
>
255
{
t
.
Fatalf
(
"Too long grpc serverConfig (>255): %d"
,
len
(
lbTXT
))
}
}
func
TestParseTraffic
(
t
*
testing
.
T
)
{
func
TestParseTraffic
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
input
string
input
string
...
...
plugin/traffic/traffic.go
View file @
e2238cfa
...
@@ -69,10 +69,9 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
...
@@ -69,10 +69,9 @@ func (t *Traffic) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
return
0
,
nil
return
0
,
nil
}
}
if
strings
.
HasPrefix
(
strings
.
ToLower
(
labels
[
0
]),
"_grpc_config"
)
{
if
strings
.
HasPrefix
(
strings
.
ToLower
(
labels
[
0
]),
"_grpc_config"
)
{
// this is the grpc config blob encoded in a TXT record, we just return a NXDOMAIN
// this is the grpc config blob encoded in a TXT record, see documentation for lbTXT.
// make this a separate so we can insert some logic later.
m
.
Answer
=
txt
(
state
.
Zone
)
m
.
Ns
=
soa
(
state
.
Zone
)
m
.
Rcode
=
dns
.
RcodeSuccess
m
.
Rcode
=
dns
.
RcodeNameError
w
.
WriteMsg
(
m
)
w
.
WriteMsg
(
m
)
return
0
,
nil
return
0
,
nil
...
...
plugin/traffic/traffic_test.go
View file @
e2238cfa
...
@@ -125,7 +125,7 @@ func TestTraffic(t *testing.T) {
...
@@ -125,7 +125,7 @@ func TestTraffic(t *testing.T) {
{
"127.0.0.2"
,
18008
,
corepb
.
HealthStatus_HEALTHY
},
{
"127.0.0.2"
,
18008
,
corepb
.
HealthStatus_HEALTHY
},
}),
}),
},
},
cluster
:
"_grpc_config.web"
,
qtype
:
dns
.
TypeTXT
,
rcode
:
dns
.
Rcode
NameError
,
ns
:
true
,
cluster
:
"_grpc_config.web"
,
qtype
:
dns
.
TypeTXT
,
rcode
:
dns
.
Rcode
Success
,
},
},
}
}
...
...
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