xdsclient

package
v1.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright Authors of Cilium

Index

Constants

This section is empty.

Variables

View Source
var Cell = cell.Module(
	"xds-client",
	"Client library handling xds DiscoveryRequests with gRPC transport protocol",

	cell.Provide(newConnectionOptions),
	cell.Provide(newXDSClient),
	cell.Invoke(runXDSClient),
	cell.Config(defaultConfig),
)

Cell defines a new module for xDS client. Cell requires providing: * DialOptionsProvider for configuring Dial Options for gRPC connection. * NodeProvider for building xds Node

View Source
var Defaults = ConnectionOptions{
	RetryBackoff: BackoffParams{
		Min:   time.Second,
		Max:   time.Minute,
		Reset: 2 * time.Minute,
	},

	IsRetriable: func(code codes.Code) bool {
		switch code {
		case codes.PermissionDenied, codes.Aborted, codes.Unauthenticated, codes.Unavailable, codes.Canceled:
			return false
		}
		return true
	},
}

Functions

This section is empty.

Types

type BackoffParams

type BackoffParams struct {
	Min, Max, Reset time.Duration
}

type Client

type Client interface {
	// Observe adds resources of given type url and names to the attention set
	// of the client.
	Observe(ctx context.Context, typeUrl string, resourceNames []string) error

	// AddResourceWatcher registers a callback cb that will be invoked every
	// time a resource with given type url changes. Function returns a callback
	// to deregister the watcher.
	AddResourceWatcher(typeUrl string, cb WatcherCallback) func()

	// Run initialize the node and start an AggregatedDiscoverService stream.
	// Requests and responses are processed until provided Context ctx is
	// done or non-retriable error occurs.
	Run(ctx context.Context, node *corepb.Node, conn grpc.ClientConnInterface) error
}

Client is the public interface of xDS client.

func NewClient

func NewClient(log *slog.Logger, useSOTW bool, opts *ConnectionOptions) Client

NewClient creates a new instance of XDSClient using sotw or delta protocol flavour based on options opts.

type Config

type Config struct {
	ServerAddr string `mapstructure:"xds-server-address"`
	UseSOTW    bool   `mapstructure:"xds-use-sotw-protocol"`
	NodeID     string `mapstructure:"xds-node-id"`
}

func (Config) Flags

func (conf Config) Flags(flags *pflag.FlagSet)

Flags implements Flagger interface

type ConnectionOptions

type ConnectionOptions struct {
	RetryBackoff    BackoffParams
	RetryConnection bool
	IsRetriable     func(code codes.Code) (retry bool)
}

type DialOptionsProvider

type DialOptionsProvider interface {
	GRPCOptions(context.Context) ([]grpc.DialOption, error)
}

func NewInsecureGRPCOptionsProvider

func NewInsecureGRPCOptionsProvider() DialOptionsProvider

NewInsecureGRPCOptionsProvider creates dial options provider for insecure GRPC connections.

type NodeProvider

type NodeProvider interface {
	Node(nodeID, zone string) *corepb.Node
}

func NewDefaultNodeProvider

func NewDefaultNodeProvider() NodeProvider

NewDefaultNodeProvider creates node provider for building default xds Node.

type WatcherCallback

type WatcherCallback func(res *xds.VersionedResources)

WatcherCallback will be called when a new version of a resource it was registered on appears. res will contain all resources of this type.

type XDSClient

type XDSClient[ReqT requestConstraint, RespT responseConstraint] struct {
	// contains filtered or unexported fields
}

XDSClient is a common part of xDS gRPC client implementation using flavour to implement xDS protocol version specific behaviors.

func (*XDSClient[ReqT, RespT]) AddResourceWatcher

func (c *XDSClient[ReqT, RespT]) AddResourceWatcher(typeUrl string, cb WatcherCallback) func()

func (*XDSClient[ReqT, RespT]) Observe

func (c *XDSClient[ReqT, RespT]) Observe(ctx context.Context, typeUrl string, resourceNames []string) error

Observe adds resourceNames to watched resources of a given typeUrl. It will be sent to a server asynchronously.

func (*XDSClient[ReqT, RespT]) Run

func (c *XDSClient[ReqT, RespT]) Run(ctx context.Context, node *corepb.Node, conn grpc.ClientConnInterface) error

Run initialize the node and start an AggregatedDiscoverService stream. Then requests and responses are processed until provided Context ctx is done or non-retriable error occurs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL