From ec151309dd7e2f39455bc861280c1ab0adc78d9b Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 16 Jan 2020 09:16:05 +0100 Subject: [PATCH] Implement TO Signed-off-by: Miek Gieben --- plugin/traffic/HACKING.md | 2 +- plugin/traffic/README.md | 18 ++++++++++-------- plugin/traffic/setup.go | 28 +++++++++++++++++++++++----- plugin/traffic/setup_test.go | 4 ++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/plugin/traffic/HACKING.md b/plugin/traffic/HACKING.md index 37d352ef8..f82c2c67b 100644 --- a/plugin/traffic/HACKING.md +++ b/plugin/traffic/HACKING.md @@ -33,7 +33,7 @@ Then for CoreDNS, check out the `traffic` branch, create a Corefile: ~~~ Corefile example.org { - traffic { + traffic grpc://127.0.0.1:18000 { id test-id } debug diff --git a/plugin/traffic/README.md b/plugin/traffic/README.md index 2db909da2..a9396b9f5 100644 --- a/plugin/traffic/README.md +++ b/plugin/traffic/README.md @@ -53,7 +53,7 @@ traffic { ~~~ corefile example.org { - traffic + traffic grpc://127.0.0.1:18000 debug log } @@ -62,6 +62,14 @@ example.org { 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. +## 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 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 the load reporting highly inaccurate. -## 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 +Multiple **TO** addresses is not implemented. diff --git a/plugin/traffic/setup.go b/plugin/traffic/setup.go index 010a9858c..debeb7912 100644 --- a/plugin/traffic/setup.go +++ b/plugin/traffic/setup.go @@ -1,12 +1,16 @@ package traffic import ( + "fmt" "math/rand" + "strings" "time" "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" 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/caddyserver/caddy" @@ -18,7 +22,7 @@ func init() { plugin.Register("traffic", setup) } func setup(c *caddy.Controller) error { rand.Seed(int64(time.Now().Nanosecond())) - t, err := parse(c) + t, err := parseTraffic(c) if err != nil { return plugin.Error("traffic", err) } @@ -48,14 +52,27 @@ func setup(c *caddy.Controller) error { return nil } -func parse(c *caddy.Controller) (*Traffic, error) { +func parseTraffic(c *caddy.Controller) (*Traffic, error) { node := "coredns" + toHosts := []string{} + var err error for c.Next() { args := c.RemainingArgs() - if len(args) != 0 { + if len(args) < 1 { 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() { 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 { return nil, err } diff --git a/plugin/traffic/setup_test.go b/plugin/traffic/setup_test.go index 21690df4f..28618e7f0 100644 --- a/plugin/traffic/setup_test.go +++ b/plugin/traffic/setup_test.go @@ -15,7 +15,7 @@ func TestSetup(t *testing.T) { */ } -func TestParse(t *testing.T) { +func TestParseTraffic(t *testing.T) { tests := []struct { input string shouldErr bool @@ -30,7 +30,7 @@ func TestParse(t *testing.T) { } for i, test := range tests { c := caddy.NewTestController("dns", test.input) - _, err := parse(c) + _, err := parseTraffic(c) if test.shouldErr && err == nil { t.Errorf("Test %v: Expected error but found nil", i) continue