Documentation ¶
Index ¶
- func ConfigInitialRequests() []*discovery.DiscoveryRequest
- type ADSC
- func (a *ADSC) Close()
- func (a *ADSC) Dial() error
- func (a *ADSC) EndpointsJSON() string
- func (a *ADSC) GetClusters() map[string]*cluster.Cluster
- func (a *ADSC) GetEdsClusters() map[string]*cluster.Cluster
- func (a *ADSC) GetEndpoints() map[string]*endpoint.ClusterLoadAssignment
- func (a *ADSC) GetHTTPListeners() map[string]*listener.Listener
- func (a *ADSC) GetRoutes() map[string]*route.RouteConfiguration
- func (a *ADSC) GetTCPListeners() map[string]*listener.Listener
- func (a *ADSC) HasSynced() bool
- func (a *ADSC) Run() error
- func (a *ADSC) Save(base string) error
- func (a *ADSC) Send(req *discovery.DiscoveryRequest) error
- func (a *ADSC) Wait(to time.Duration, updates ...string) ([]string, error)
- func (a *ADSC) WaitClear()
- func (a *ADSC) WaitSingle(to time.Duration, want string, reject string) error
- func (a *ADSC) WaitVersion(to time.Duration, typeURL, lastVersion string) (*discovery.DiscoveryResponse, error)
- type ADSConfig
- type Client
- type Config
- type DeltaADSConfig
- type DeltaAggregatedResourcesClient
- type Event
- type HandlerContext
- type HandlerFunc
- type Option
- type Resource
- type ResponseHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigInitialRequests ¶
func ConfigInitialRequests() []*discovery.DiscoveryRequest
Types ¶
type ADSC ¶
type ADSC struct { // Updates includes the type of the last update received from the server. Updates chan string XDSUpdates chan *discovery.DiscoveryResponse VersionInfo map[string]string // Last received message, by type Received map[string]*discovery.DiscoveryResponse Mesh *v1alpha1.MeshConfig // Retrieved configurations can be stored using the common istio model interface. Store model.ConfigStore // Retrieved endpoints can be stored in the memory registry. This is used for CDS and EDS responses. Registry *memory.ServiceDiscovery // contains filtered or unexported fields }
ADSC implements a basic client for ADS, for use in stress tests and tools or libraries that need to connect to Istio pilot or other ADS servers.
func New ¶
New creates a new ADSC, maintaining a connection to an XDS server. Will: - get certificate using the Secret provider, if CertRequired - connect to the XDS server specified in ProxyConfig - send initial request for watched resources - wait for response from XDS server - on success, start a background thread to maintain the connection, with exp. backoff.
func NewWithBackoffPolicy ¶
func (*ADSC) Dial ¶
Dial connects to a ADS server, with optional MTLS authentication if a cert dir is specified.
func (*ADSC) EndpointsJSON ¶
EndpointsJSON returns the endpoints, formatted as JSON, for debugging.
func (*ADSC) GetClusters ¶
GetClusters returns all the non-eds type clusters.
func (*ADSC) GetEdsClusters ¶
GetEdsClusters returns all the eds type clusters.
func (*ADSC) GetEndpoints ¶
func (a *ADSC) GetEndpoints() map[string]*endpoint.ClusterLoadAssignment
GetEndpoints returns all the routes.
func (*ADSC) GetHTTPListeners ¶
GetHTTPListeners returns all the http listeners.
func (*ADSC) GetRoutes ¶
func (a *ADSC) GetRoutes() map[string]*route.RouteConfiguration
GetRoutes returns all the routes.
func (*ADSC) GetTCPListeners ¶
GetTCPListeners returns all the tcp listeners.
func (*ADSC) Run ¶
Run will create a new stream using the existing grpc client connection and send the initial xds requests. And then it will run a go routine receiving and handling xds response. Note: it is non blocking
func (*ADSC) Send ¶
func (a *ADSC) Send(req *discovery.DiscoveryRequest) error
Raw send of a request.
func (*ADSC) Wait ¶
Wait for an updates for all the specified types If updates is empty, this will wait for any update
func (*ADSC) WaitClear ¶
func (a *ADSC) WaitClear()
WaitClear will clear the waiting events, so next call to Wait will get the next push type.
func (*ADSC) WaitSingle ¶
WaitSingle waits for a single resource, and fails if the rejected type is returned. We avoid rejecting all other types to avoid race conditions. For example, a test asserting an incremental update of EDS may fail if a previous push's RDS response comes in later. Instead, we can reject events coming before (ie CDS). The only real alternative is to wait which introduces its own issues.
func (*ADSC) WaitVersion ¶
func (a *ADSC) WaitVersion(to time.Duration, typeURL, lastVersion string) (*discovery.DiscoveryResponse, error)
WaitVersion waits for a new or updated for a typeURL.
type ADSConfig ¶
type ADSConfig struct { Config // InitialDiscoveryRequests is a list of resources to watch at first, represented as URLs (for new XDS resource naming) // or type URLs. InitialDiscoveryRequests []*discovery.DiscoveryRequest // ResponseHandler will be called on each DiscoveryResponse. // TODO: mirror Generator, allow adding handler per type ResponseHandler ResponseHandler }
ADSConfig for the ADS connection.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a stateful ADS (Aggregated Discovery Service) client designed to handle delta updates from an xDS server. Central to this client is a dynamic 'tree' of resources, representing the relationships and states of resources in the service mesh. The client's operation unfolds in the following steps:
Sending Initial Requests: The client initiates requests for resources it needs, as specified by the Watch function. This step sets the stage for receiving relevant DeltaDiscoveryResponse from the server.
Processing DeltaDiscoveryResponses: Upon receiving a delta response, the client performs several key actions: - Event Handling: Triggers specific handlers for each resource, as register using Register function during client initialization. - Tree Update: Modifies its 'tree' to reflect changes in resources, such as adding new resources, updating relationships between parents and children, and removing or unlinking resources.
State Synchronization: Post-processing the delta response, the client updates its internal state. This involves: - Acknowledgements and Errors: Communicating acknowledgements or errors back to the server based on the processing outcome. In cases of error or rejection, a Nack can be sent using HandlerContext.Reject. - Dependency Updates: Triggering requests for dependent resources. These dependencies are established via HandlerContext.RegisterDependency.
An example of a handler registration is as follows:
clusterHandler := Register(func(ctx HandlerContext, res *cluster.Cluster, event Event) { if event == EventDelete { return } ctx.RegisterDependency(v3.SecretType, ExtractClusterSecretResources(t, res)...) ctx.RegisterDependency(v3.EndpointType, ExtractEdsClusterNames([]*cluster.Cluster{res})...) })
It means that when a cluster is added or updated, the client will trigger requests for the secrets and endpoints that the cluster depends on.
An example of register handlers:
handlers := []Option{ clusterHandler, Watch[*cluster.Cluster]("*"), listenerHandler, Watch[*listener.Listener]("*"), endpointsHandler, routesHandler, secretsHandler, }
client := NewDelta("localhost:8080", handlers...)
It means that the client will watch all clusters and listeners, and trigger resource events for clusters, listeners, endpoints, routes and secrets that the clusters and listeners depend on.
type Config ¶
type Config struct { // Is the name of the client for user-facing logs. If not set, Address will be used ClientName string // Address of the xDS server Address string // XDSSAN is the expected SAN of the XDS server. If not set, the ProxyConfig.DiscoveryAddress is used. XDSSAN string // Namespace defaults to 'default' Namespace string // Workload defaults to 'test' Workload string // Revision for this control plane instance. We will only read configs that match this revision. Revision string // Meta includes additional metadata for the node Meta *pstruct.Struct Locality *core.Locality // NodeType defaults to sidecar. "ingress" and "router" are also supported. NodeType model.NodeType // IP is currently the primary key used to locate inbound configs. It is sent by client, // must match a known endpoint IP. Tests can use a ServiceEntry to register fake IPs. IP string // CertDir is the directory where mTLS certs are configured. // If CertDir and Secret are empty, an insecure connection will be used. // TODO: implement SecretManager for cert dir CertDir string // Secrets is the interface used for getting keys and rootCA. SecretManager security.SecretManager // XDSRootCAFile explicitly set the root CA to be used for the XDS connection. // Mirrors Envoy file. XDSRootCAFile string // InsecureSkipVerify skips client verification the server's certificate chain and host name. InsecureSkipVerify bool // BackoffPolicy determines the reconnect policy. Based on MCP client. BackoffPolicy backoff.BackOff GrpcOpts []grpc.DialOption }
type DeltaADSConfig ¶
type DeltaADSConfig struct {
Config
}
DeltaADSConfig for delta ADS connection.
type DeltaAggregatedResourcesClient ¶
type DeltaAggregatedResourcesClient interface { Send(*discovery.DeltaDiscoveryRequest) error Recv() (*discovery.DeltaDiscoveryResponse, error) CloseSend() error }
type HandlerContext ¶
type HandlerFunc ¶
type HandlerFunc func(ctx HandlerContext, res *Resource, event Event)
type Option ¶
type Option func(c *Client)
type ResponseHandler ¶
type ResponseHandler interface {
HandleResponse(con *ADSC, response *discovery.DiscoveryResponse)
}