Skip to main content

xDS

xds

import "github.com/gojek/courier-go/xds"

Package xds contains the client that can be used to interact with the management server to receive address updates for subscribed clusters

Index

## type [Client](https://github.com/gojek/courier-go/blob/main/xds/client.go#L69-L80)

Client performs the actual ADS RPCs using the ADS v3 API. It creates an ADS stream on which the xdsTarget resources are received.

type Client struct {
// contains filtered or unexported fields
}
### func [NewClient](https://github.com/gojek/courier-go/blob/main/xds/client.go#L40)
func NewClient(opts Options) *Client

NewClient returns a new ADS client stream using the *grpc.ClientConn provided.

### func \(\*Client\) [Done](https://github.com/gojek/courier-go/blob/main/xds/client.go#L88)
func (c *Client) Done() <-chan struct{}

Done returns a channel which is closed when the run loop stops due to context expiry

### func \(\*Client\) [Receive](https://github.com/gojek/courier-go/blob/main/xds/client.go#L83)
func (c *Client) Receive() <-chan []*v3endpointpb.ClusterLoadAssignment

Receive returns a channel where ClusterLoadAssignment resource updates can be received

### func \(\*Client\) [Start](https://github.com/gojek/courier-go/blob/main/xds/client.go#L93)
func (c *Client) Start(ctx context.Context) error

Start will wait updates from control plane, it is non-blocking

## type [Options](https://github.com/gojek/courier-go/blob/main/xds/client.go#L31-L37)

Options specifies options to be provided for initialising the xds client

type Options struct {
XDSTarget string
NodeProto *v3corepb.Node
ClientConn grpc.ClientConnInterface
BackoffStrategy backoff.Strategy
Logger log.Logger
}
## type [Resolver](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L17-L20)

Resolver sends updates to via the channel returned by UpdateChan()

type Resolver struct {
// contains filtered or unexported fields
}
### func [NewResolver](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L23)
func NewResolver(rc clusterUpdateReceiver) *Resolver

NewResolver returns a *Resolver that uses rc to receive cluster updates

Example

cfg, err := bootstrap.NewConfigFromContents([]byte(`{
"xds_server": {
"server_uri": "localhost:9100",
"node": {
"id": "52fdfc07-2182-454f-963f-5f0f9a621d72",
"cluster": "cluster",
"metadata": {
"TRAFFICDIRECTOR_GCP_PROJECT_NUMBER": "123456789012345",
"TRAFFICDIRECTOR_NETWORK_NAME": "thedefault"
},
"locality": {
"zone": "uscentral-5"
}
}
}
}`,
))
if err != nil {
panic(err)
}

ctx, _ := signal.NotifyContext(context.Background(), os.Kill, os.Interrupt)

cc, err := grpc.DialContext(ctx, cfg.XDSServer.ServerURI, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
panic(err)
}

xdsClient := xds.NewClient(xds.Options{
XDSTarget: "xds:///broker.domain",
NodeProto: cfg.XDSServer.NodeProto.(*corev3.Node),
ClientConn: cc,
BackoffStrategy: &backoff.DefaultExponential,
})

if err := xdsClient.Start(ctx); err != nil {
panic(err)
}

r := xds.NewResolver(xdsClient)

c, err := courier.NewClient(courier.WithResolver(r))
if err != nil {
panic(err)
}

if err := c.Start(); err != nil {
panic(err)
}

<-ctx.Done()

### func \(\*Resolver\) [Done](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L40)
func (r *Resolver) Done() <-chan struct{}

Done returns a channel which is closed when the underlying clusterUpdateReceiver is marked as done

### func \(\*Resolver\) [UpdateChan](https://github.com/gojek/courier-go/blob/main/xds/resolver.go#L35)
func (r *Resolver) UpdateChan() <-chan []courier.TCPAddress

UpdateChan returns a channel where []courier.TCPAddress can be received

Generated by gomarkdoc