package xdsclient

import "google.golang.org/grpc/xds/internal/clients/xdsclient"

Package xdsclient provides an xDS (* Discovery Service) client.

It allows applications to:

This enables applications to dynamically discover and configure resources such as listeners, routes, clusters, and endpoints from an xDS management server.

Index

Types

type Authority

type Authority struct {
	// XDSServers contains the list of server configurations for this authority.
	//
	// See Config.Servers for more details.
	XDSServers []ServerConfig
}

Authority contains configuration for an xDS control plane authority.

See: https://www.envoyproxy.io/docs/envoy/latest/xds/core/v3/resource_locator.proto#xds-core-v3-resourcelocator

type Config

type Config struct {
	// Servers specifies a list of xDS management servers to connect to. The
	// order of the servers in this list reflects the order of preference of
	// the data returned by those servers. The xDS client uses the first
	// available server from the list.
	//
	// See gRFC A71 for more details on fallback behavior when the primary
	// xDS server is unavailable.
	//
	// gRFC A71: https://github.com/grpc/proposal/blob/master/A71-xds-fallback.md
	Servers []ServerConfig

	// Authorities defines the configuration for each xDS authority.  Federated resources
	// will be fetched from the servers specified by the corresponding Authority.
	Authorities map[string]Authority

	// Node is the identity of the xDS client connecting to the xDS
	// management server.
	Node clients.Node

	// TransportBuilder is used to create connections to xDS management servers.
	TransportBuilder clients.TransportBuilder

	// ResourceTypes is a map from resource type URLs to resource type
	// implementations. Each resource type URL uniquely identifies a specific
	// kind of xDS resource, and the corresponding resource type implementation
	// provides logic for parsing, validating, and processing resources of that
	// type.
	//
	// For example: "type.googleapis.com/envoy.config.listener.v3.Listener"
	ResourceTypes map[string]ResourceType
}

Config is used to configure an xDS client. After one has been passed to the xDS client's New function, no part of it may be modified. A Config may be reused; the xdsclient package will also not modify it.

type DecodeOptions

type DecodeOptions struct {
	// Config contains the complete configuration passed to the xDS client.
	// This contains useful data for resource validation.
	Config *Config

	// ServerConfig contains the configuration of the xDS server that provided
	// the current resource being decoded.
	ServerConfig *ServerConfig
}

DecodeOptions wraps the options required by ResourceType implementations for decoding configuration received from the xDS management server.

type DecodeResult

type DecodeResult struct {
	// Name is the name of the decoded resource.
	Name string

	// Resource contains the configuration associated with the decoded
	// resource.
	Resource ResourceData
}

DecodeResult is the result of a decode operation.

type Decoder

type Decoder interface {
	// Decode deserializes and validates an xDS resource as received from the
	// xDS management server.
	//
	// If deserialization fails or resource validation fails, it returns a
	// non-nil error. Otherwise, returns a fully populated DecodeResult.
	Decode(resource []byte, options DecodeOptions) (*DecodeResult, error)
}

Decoder wraps the resource-type specific functionality for validation and deserialization.

type ResourceData

type ResourceData interface {
	// Equal returns true if the passed in resource data is equal to that of
	// the receiver.
	Equal(other ResourceData) bool

	// Bytes returns the underlying raw bytes of the resource proto.
	Bytes() []byte
}

ResourceData contains the configuration data sent by the xDS management server, associated with the resource being watched. Every resource type must provide an implementation of this interface to represent the configuration received from the xDS management server.

type ResourceType

type ResourceType struct {
	// TypeURL is the xDS type URL of this resource type for the v3 xDS
	// protocol. This URL is used as the key to look up the corresponding
	// ResourceType implementation in the ResourceTypes map provided in the
	// Config.
	TypeURL string

	// TypeName is a shorter representation of the TypeURL to identify the
	// resource type. It is used for logging/debugging purposes.
	TypeName string

	// AllResourcesRequiredInSotW indicates whether this resource type requires
	// that all resources be present in every SotW response from the server. If
	// true, a response that does not include a previously seen resource will
	// be interpreted as a deletion of that resource.
	AllResourcesRequiredInSotW bool

	// Decoder is used to deserialize and validate an xDS resource received
	// from the xDS management server.
	Decoder Decoder
}

ResourceType wraps all resource-type specific functionality. Each supported resource type needs to provide an implementation of the Decoder.

type ResourceWatcher

type ResourceWatcher interface {
	// ResourceChanged indicates a new version of the resource is available.
	ResourceChanged(resourceData ResourceData, done func())

	// ResourceError indicates an error occurred while trying to fetch or
	// decode the associated resource. The previous version of the resource
	// should be considered invalid.
	ResourceError(err error, done func())

	// AmbientError indicates an error occurred after a resource has been
	// received that should not modify the use of that resource but may provide
	// useful information about the state of the XDSClient for debugging
	// purposes. The previous version of the resource should still be
	// considered valid.
	AmbientError(err error, done func())
}

ResourceWatcher is notified of the resource updates and errors that are received by the xDS client from the management server.

All methods contain a done parameter which should be called when processing of the update has completed. For example, if processing a resource requires watching new resources, those watches should be completed before done is called, which can happen after the ResourceWatcher method has returned. Failure to call done will prevent the xDS client from providing future ResourceWatcher notifications.

type ServerConfig

type ServerConfig struct {
	ServerIdentifier clients.ServerIdentifier

	// IgnoreResourceDeletion is a server feature which if set to true,
	// indicates that resource deletion errors from xDS management servers can
	// be ignored and cached resource data can be used.
	//
	// This will be removed in the future once we implement gRFC A88
	// and two new fields FailOnDataErrors and
	// ResourceTimerIsTransientError will be introduced.
	IgnoreResourceDeletion bool
}

ServerConfig contains configuration for an xDS management server.

type XDSClient

type XDSClient struct {
}

XDSClient is a client which queries a set of discovery APIs (collectively termed as xDS) on a remote management server, to discover various dynamic resources.

func New

func New(config Config) (*XDSClient, error)

New returns a new xDS Client configured with the provided config.

func (*XDSClient) Close

func (c *XDSClient) Close() error

Close closes the xDS client.

func (*XDSClient) DumpResources

func (c *XDSClient) DumpResources() []byte

DumpResources returns the status and contents of all xDS resources being watched by the xDS client.

func (*XDSClient) WatchResource

func (c *XDSClient) WatchResource(typeURL, name string, watcher ResourceWatcher) (cancel func())

WatchResource starts watching the specified resource.

typeURL specifies the resource type implementation to use. The watch fails if there is no resource type implementation for the given typeURL. See the ResourceTypes field in the Config struct used to create the XDSClient.

The returned function cancels the watch and prevents future calls to the watcher.

Source Files

ads_stream.go channel.go resource_type.go resource_watcher.go xdsclient.go xdsconfig.go

Directories

PathSynopsis
xds/internal/clients/xdsclient/internal
xds/internal/clients/xdsclient/internal/xdsresourcePackage xdsresource defines constants to distinguish between supported xDS API versions.
Version
v1.72.0 (latest)
Published
Apr 21, 2025
Platform
linux/amd64
Imports
22 packages
Last checked
13 minutes ago

Tools for package owners.