Implement TO

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-16 09:16:05 +01:00
parent def3238287
commit ec151309dd
4 changed files with 36 additions and 16 deletions

View File

@@ -33,7 +33,7 @@ Then for CoreDNS, check out the `traffic` branch, create a Corefile:
~~~ Corefile ~~~ Corefile
example.org { example.org {
traffic { traffic grpc://127.0.0.1:18000 {
id test-id id test-id
} }
debug debug

View File

@@ -53,7 +53,7 @@ traffic {
~~~ corefile ~~~ corefile
example.org { example.org {
traffic traffic grpc://127.0.0.1:18000
debug debug
log log
} }
@@ -62,6 +62,14 @@ example.org {
This will add load balancing for domains under example.org; the upstream information comes from This will add load balancing for domains under example.org; the upstream information comes from
10.12.13.14; depending on received assignments, replies will be let through as-is or are load balanced. 10.12.13.14; depending on received assignments, replies will be let through as-is or are load balanced.
## Also See
The following documents provide some background on Envoy's control plane.
* https://github.com/envoyproxy/go-control-plane
* https://blog.christianposta.com/envoy/guidance-for-building-a-control-plane-to-manage-envoy-proxy-based-infrastructure/
* https://github.com/envoyproxy/envoy/blob/442f9fcf21a5f091cec3fe9913ff309e02288659/api/envoy/api/v2/discovery.proto#L63
## Bugs ## Bugs
Priority from ClusterLoadAssignments is not used. Locality is also not used. Health status of the Priority from ClusterLoadAssignments is not used. Locality is also not used. Health status of the
@@ -73,10 +81,4 @@ clients that will use this reply, the responding server (CoreDNS) has no idea ho
this resolver. So reporting a load of +1 on the CoreDNS side can be anything from 1 to 1000+, making this resolver. So reporting a load of +1 on the CoreDNS side can be anything from 1 to 1000+, making
the load reporting highly inaccurate. the load reporting highly inaccurate.
## Also See Multiple **TO** addresses is not implemented.
The following documents provide some background on Envoy's control plane.
* https://github.com/envoyproxy/go-control-plane
* https://blog.christianposta.com/envoy/guidance-for-building-a-control-plane-to-manage-envoy-proxy-based-infrastructure/
* https://github.com/envoyproxy/envoy/blob/442f9fcf21a5f091cec3fe9913ff309e02288659/api/envoy/api/v2/discovery.proto#L63

View File

@@ -1,12 +1,16 @@
package traffic package traffic
import ( import (
"fmt"
"math/rand" "math/rand"
"strings"
"time" "time"
"github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
"github.com/coredns/coredns/plugin/pkg/transport"
"github.com/coredns/coredns/plugin/traffic/xds" "github.com/coredns/coredns/plugin/traffic/xds"
"github.com/caddyserver/caddy" "github.com/caddyserver/caddy"
@@ -18,7 +22,7 @@ func init() { plugin.Register("traffic", setup) }
func setup(c *caddy.Controller) error { func setup(c *caddy.Controller) error {
rand.Seed(int64(time.Now().Nanosecond())) rand.Seed(int64(time.Now().Nanosecond()))
t, err := parse(c) t, err := parseTraffic(c)
if err != nil { if err != nil {
return plugin.Error("traffic", err) return plugin.Error("traffic", err)
} }
@@ -48,14 +52,27 @@ func setup(c *caddy.Controller) error {
return nil return nil
} }
func parse(c *caddy.Controller) (*Traffic, error) { func parseTraffic(c *caddy.Controller) (*Traffic, error) {
node := "coredns" node := "coredns"
toHosts := []string{}
var err error
for c.Next() { for c.Next() {
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) != 0 { if len(args) < 1 {
return nil, c.ArgErr() return nil, c.ArgErr()
}
toHosts, err = parse.HostPortOrFile(args...)
if err != nil {
return nil, err
}
for i := range toHosts {
if !strings.HasPrefix(toHosts[i], transport.GRPC+"://") {
return nil, fmt.Errorf("not a %s scheme: %s", transport.GRPC, toHosts[i])
}
// now cut the prefix off again, because the dialer needs to see normal address strings. All this
// grpc:// stuff is to enfore uniformaty accross plugins and future proofing for other protocols.
toHosts[i] = toHosts[i][len(transport.GRPC+"://"):]
} }
for c.NextBlock() { for c.NextBlock() {
switch c.Val() { switch c.Val() {
@@ -71,7 +88,8 @@ func parse(c *caddy.Controller) (*Traffic, error) {
} }
} }
x, err := xds.New(":18000", node) // TODO: only the first host is used.
x, err := xds.New(toHosts[0], node)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -15,7 +15,7 @@ func TestSetup(t *testing.T) {
*/ */
} }
func TestParse(t *testing.T) { func TestParseTraffic(t *testing.T) {
tests := []struct { tests := []struct {
input string input string
shouldErr bool shouldErr bool
@@ -30,7 +30,7 @@ func TestParse(t *testing.T) {
} }
for i, test := range tests { for i, test := range tests {
c := caddy.NewTestController("dns", test.input) c := caddy.NewTestController("dns", test.input)
_, err := parse(c) _, err := parseTraffic(c)
if test.shouldErr && err == nil { if test.shouldErr && err == nil {
t.Errorf("Test %v: Expected error but found nil", i) t.Errorf("Test %v: Expected error but found nil", i)
continue continue