Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-13 11:21:20 +01:00
parent 722133881b
commit 519ef9ca79
6 changed files with 52 additions and 3 deletions

View File

@@ -18,3 +18,22 @@ https://github.com/envoyproxy/learnenvoy/blob/master/_articles/service-discovery
Cluster: A cluster is a group of logically similar endpoints that Envoy connects to. In v2, RDS
routes points to clusters, CDS provides cluster configuration and Envoy discovers the cluster
members via EDS.
# Testing
~~~ sh
$ cd ~/src/github.com/envoyproxy/go-control-plane
% make integration.xds
~~~
This runs a binary from pkg/test/main. Now we're testing xDS, but there is also aDS (which does
everything including xDS). I'm still figuring out what do to here.
The script stops, unless you have Envoy installed (which I haven't), but you can run it manually:
~~~ sh
./bin/test --xds=xds --runtimes=1 -debug # for xds
~~~
This fails with `timeout waiting for the first request`, means you're consumer wasn't quick enough
in asking for xDS assignments.

View File

@@ -42,6 +42,17 @@ Findign the xDS endpoint.
traffic
~~~
The extended syntax:
~~~
traffic {
server grpc://dsdsd <creds>
id ID
}
~~~
* id **ID** is how *traffic* identifies itself to the control plane.
This enables traffic load balancing for all (sub-)domains named in the server block.
## Examples

View File

@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/traffic/xds"
"github.com/caddyserver/caddy"
)
@@ -31,6 +32,8 @@ func setup(c *caddy.Controller) error {
return t
})
t.c.WatchCluster("xds_experimental", func(xds.CDSUpdate, error) {})
return nil
}

View File

@@ -69,6 +69,8 @@ func New(opts Options) (*Client, error) {
return nil, fmt.Errorf("xds: failed to dial balancer {%s}: %v", opts.Config.BalancerName, err)
}
println("dialed balancer at", opts.Config.BalancerName)
c := &Client{
opts: opts,
cc: cc,
@@ -85,6 +87,10 @@ func (c *Client) Close() {
c.cc.Close()
}
func (c *Client) Run() {
c.v2c.run()
}
// ServiceUpdate contains update about the service.
type ServiceUpdate struct {
Cluster string

View File

@@ -127,12 +127,14 @@ func (v2c *v2Client) run() {
}
retries++
println("SENDING STUFF, retries", retries)
cli := adsgrpc.NewAggregatedDiscoveryServiceClient(v2c.cc)
stream, err := cli.StreamAggregatedResources(v2c.ctx, grpc.WaitForReady(true))
stream, err := cli.StreamAggregatedResources(v2c.ctx) //, grpc.WaitForReady(true))
if err != nil {
log.Infof("xds: ADS stream creation failed: %v", err)
continue
}
println("created ads stream")
// send() could be blocked on reading updates from the different update
// channels when it is not actually sending out messages. So, we need a
@@ -143,11 +145,12 @@ func (v2c *v2Client) run() {
if v2c.recv(stream) {
retries = 0
}
println("sending has succeeded")
close(done)
}
}
// sendRequest sends a request for provided typeURL and resource on the provided
// endRequest sends a request for provided typeURL and resource on the provided
// stream.
//
// version is the ack version to be sent with the request
@@ -261,9 +264,12 @@ func (v2c *v2Client) processAckInfo(t *ackInfo) (target []string, typeURL, versi
// on the provided ADS stream.
func (v2c *v2Client) send(stream adsStream, done chan struct{}) {
if !v2c.sendExisting(stream) {
println("not existing stream")
return
}
println("in send")
for {
select {
case <-v2c.ctx.Done():
@@ -278,8 +284,10 @@ func (v2c *v2Client) send(stream adsStream, done chan struct{}) {
)
switch t := u.(type) {
case *watchInfo:
println("watchInfo")
target, typeURL, version, nonce, send = v2c.processWatchInfo(t)
case *ackInfo:
println("ackInfo")
target, typeURL, version, nonce, send = v2c.processAckInfo(t)
}
if !send {
@@ -367,7 +375,9 @@ func (v2c *v2Client) watchEDS(clusterName string, edsCb edsCallback) (cancel fun
}
func (v2c *v2Client) watch(wi *watchInfo) (cancel func()) {
println("watch")
v2c.sendCh.Put(wi)
println("returning from watch")
return func() {
v2c.mu.Lock()
defer v2c.mu.Unlock()

View File

@@ -6,7 +6,7 @@
}
},
"xds_servers" : [{
"server_uri": "trafficdirector.googleapis.com:443",
"server_uri": "localhost:18000",
"channel_creds": [
{ "type": "google_default" }
]