Documentation ¶
Overview ¶
Package e2e provides utilities for end2end testing of xDS functionality.
Index ¶
- Constants
- Variables
- func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster
- func CreateClientTLSCredentials(t *testing.T) credentials.TransportCredentials
- func DefaultClientListener(target, routeName string) *v3listenerpb.Listener
- func DefaultCluster(clusterName, edsServiceName string, secLevel SecurityLevel) *v3clusterpb.Cluster
- func DefaultEndpoint(clusterName string, host string, ports []uint32) *v3endpointpb.ClusterLoadAssignment
- func DefaultFileWatcherConfig(certPath, keyPath, caPath string) json.RawMessage
- func DefaultRouteConfig(routeName, ldsTarget, clusterName string) *v3routepb.RouteConfiguration
- func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3listenerpb.Listener
- func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoadAssignment
- func HTTPFilter(name string, config proto.Message) *v3httppb.HttpFilter
- func RouteConfigResourceWithOptions(opts RouteConfigOptions) *v3routepb.RouteConfiguration
- type ClusterOptions
- type EndpointOptions
- type LoadBalancingPolicy
- type ManagementServer
- type ManagementServerOptions
- type ResourceParams
- type RouteConfigClusterSpecifierType
- type RouteConfigOptions
- type SecurityLevel
- type UpdateOptions
Constants ¶
const ( // ServerListenerResourceNameTemplate is the Listener resource name template // used on the server side. ServerListenerResourceNameTemplate = "grpc/server?xds.resource.listening_address=%s" // ClientSideCertProviderInstance is the certificate provider instance name // used in the Cluster resource on the client side. ClientSideCertProviderInstance = "client-side-certificate-provider-instance" // ServerSideCertProviderInstance is the certificate provider instance name // used in the Listener resource on the server side. ServerSideCertProviderInstance = "server-side-certificate-provider-instance" )
Variables ¶
var RouterHTTPFilter = HTTPFilter("router", &v3routerpb.Router{})
RouterHTTPFilter is the HTTP Filter configuration for the Router filter.
Functions ¶
func ClusterResourceWithOptions ¶ added in v1.50.0
func ClusterResourceWithOptions(opts ClusterOptions) *v3clusterpb.Cluster
ClusterResourceWithOptions returns an xDS Cluster resource configured with the provided options.
func CreateClientTLSCredentials ¶
func CreateClientTLSCredentials(t *testing.T) credentials.TransportCredentials
CreateClientTLSCredentials creates client-side TLS transport credentials using certificate and key files from testdata/x509 directory.
func DefaultClientListener ¶
func DefaultClientListener(target, routeName string) *v3listenerpb.Listener
DefaultClientListener returns a basic xds Listener resource to be used on the client side.
func DefaultCluster ¶
func DefaultCluster(clusterName, edsServiceName string, secLevel SecurityLevel) *v3clusterpb.Cluster
DefaultCluster returns a basic xds Cluster resource.
func DefaultEndpoint ¶
func DefaultEndpoint(clusterName string, host string, ports []uint32) *v3endpointpb.ClusterLoadAssignment
DefaultEndpoint returns a basic xds Endpoint resource.
func DefaultFileWatcherConfig ¶
func DefaultFileWatcherConfig(certPath, keyPath, caPath string) json.RawMessage
DefaultFileWatcherConfig is a helper function to create a default certificate provider plugin configuration. The test is expected to have setup the files appropriately before this configuration is used to instantiate providers.
func DefaultRouteConfig ¶
func DefaultRouteConfig(routeName, ldsTarget, clusterName string) *v3routepb.RouteConfiguration
DefaultRouteConfig returns a basic xds RouteConfig resource.
func DefaultServerListener ¶
func DefaultServerListener(host string, port uint32, secLevel SecurityLevel) *v3listenerpb.Listener
DefaultServerListener returns a basic xds Listener resource to be used on the server side.
func EndpointResourceWithOptions ¶ added in v1.54.0
func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoadAssignment
EndpointResourceWithOptions returns an xds Endpoint resource configured with the provided options.
func HTTPFilter ¶
func HTTPFilter(name string, config proto.Message) *v3httppb.HttpFilter
HTTPFilter constructs an xds HttpFilter with the provided name and config.
func RouteConfigResourceWithOptions ¶ added in v1.54.0
func RouteConfigResourceWithOptions(opts RouteConfigOptions) *v3routepb.RouteConfiguration
RouteConfigResourceWithOptions returns a RouteConfiguration resource configured with the provided options.
Types ¶
type ClusterOptions ¶ added in v1.50.0
type ClusterOptions struct { // ClusterName is the name of the Cluster resource. ClusterName string // ServiceName is the EDS service name of the Cluster. ServiceName string // Policy is the LB policy to be used. Policy LoadBalancingPolicy // SecurityLevel determines the security configuration for the Cluster. SecurityLevel SecurityLevel }
ClusterOptions contains options to configure a Cluster resource.
type EndpointOptions ¶ added in v1.54.0
type EndpointOptions struct { // ClusterName is the name of the Cluster resource (or EDS service name) // containing the endpoints specified below. ClusterName string // Host is the hostname of the endpoints. In our e2e tests, hostname must // always be "localhost". Host string // Ports is a set of ports on "localhost" where the endpoints corresponding // to this resource reside. Ports []uint32 // DropPercents is a map from drop category to a drop percentage. If unset, // no drops are configured. DropPercents map[string]int }
EndpointOptions contains options to configure an Endpoint (or ClusterLoadAssignment) resource.
type LoadBalancingPolicy ¶ added in v1.50.0
type LoadBalancingPolicy int
LoadBalancingPolicy determines the policy used for balancing load across endpoints in the Cluster.
const ( // LoadBalancingPolicyRoundRobin results in the use of the weighted_target // LB policy to balance load across localities and endpoints in the cluster. LoadBalancingPolicyRoundRobin LoadBalancingPolicy = iota // LoadBalancingPolicyRingHash results in the use of the ring_hash LB policy // as the leaf policy. LoadBalancingPolicyRingHash )
type ManagementServer ¶
type ManagementServer struct { // Address is the host:port on which the management server is listening for // new connections. Address string // LRSServer points to the fake LRS server implementation. Set only if the // SupportLoadReportingService option was set to true when creating this // management server. LRSServer *fakeserver.Server // contains filtered or unexported fields }
ManagementServer is a thin wrapper around the xDS control plane implementation provided by envoyproxy/go-control-plane.
func SetupManagementServer ¶
func SetupManagementServer(t *testing.T, opts ManagementServerOptions) (*ManagementServer, string, []byte, resolver.Builder, func())
SetupManagementServer performs the following: - spin up an xDS management server on a local port - set up certificates for consumption by the file_watcher plugin - creates a bootstrap file in a temporary location - creates an xDS resolver using the above bootstrap contents
Returns the following: - management server - nodeID to be used by the client when connecting to the management server - bootstrap contents to be used by the client - xDS resolver builder to be used by the client - a cleanup function to be invoked at the end of the test
func StartManagementServer ¶
func StartManagementServer(opts ManagementServerOptions) (*ManagementServer, error)
StartManagementServer initializes a management server which implements the AggregatedDiscoveryService endpoint. The management server is initialized with no resources. Tests should call the Update() method to change the resource snapshot held by the management server, as required by the test logic. When the test is done, it should call the Stop() method to cleanup resources allocated by the management server.
func (*ManagementServer) Update ¶
func (s *ManagementServer) Update(ctx context.Context, opts UpdateOptions) error
Update changes the resource snapshot held by the management server, which updates connected clients as required.
type ManagementServerOptions ¶ added in v1.49.0
type ManagementServerOptions struct { // Listener to accept connections on. If nil, a TPC listener on a local port // will be created and used. Listener net.Listener // SupportLoadReportingService, if set, results in the load reporting // service being registered on the same port as that of ADS. SupportLoadReportingService bool // AllowResourceSubSet allows the management server to respond to requests // before all configured resources are explicitly named in the request. The // default behavior that we want is for the management server to wait for // all configured resources to be requested before responding to any of // them, since this is how we have run our tests historically, and should be // set to true only for tests which explicitly require the other behavior. AllowResourceSubset bool // OnStreamOpen is called when an xDS stream is opened. The callback is // invoked with the assigned stream ID and the type URL from the incoming // request (or "" for ADS). // // Returning an error from this callback will end processing and close the // stream. OnStreamClosed will still be called. OnStreamOpen func(context.Context, int64, string) error // OnStreamClosed is called immediately prior to closing an xDS stream. The // callback is invoked with the stream ID of the stream being closed. OnStreamClosed func(int64) // OnStreamRequest is called when a request is received on the stream. The // callback is invoked with the stream ID of the stream on which the request // was received and the received request. // // Returning an error from this callback will end processing and close the // stream. OnStreamClosed will still be called. OnStreamRequest func(int64, *v3discoverypb.DiscoveryRequest) error // OnStreamResponse is called immediately prior to sending a response on the // stream. The callback is invoked with the stream ID of the stream on which // the response is being sent along with the incoming request and the outgoing // response. OnStreamResponse func(context.Context, int64, *v3discoverypb.DiscoveryRequest, *v3discoverypb.DiscoveryResponse) }
ManagementServerOptions contains options to be passed to the management server during creation.
type ResourceParams ¶
type ResourceParams struct { // DialTarget is the client's dial target. This is used as the name of the // Listener resource. DialTarget string // NodeID is the id of the xdsClient to which this update is to be pushed. NodeID string // Host is the host of the default Endpoint resource. Host string // port is the port of the default Endpoint resource. Port uint32 // SecLevel controls the security configuration in the Cluster resource. SecLevel SecurityLevel }
ResourceParams wraps the arguments to be passed to DefaultClientResources.
type RouteConfigClusterSpecifierType ¶ added in v1.54.0
type RouteConfigClusterSpecifierType int
RouteConfigClusterSpecifierType determines the cluster specifier type for the route actions configured in the returned RouteConfiguration resource.
const ( // RouteConfigClusterSpecifierTypeCluster results in the cluster specifier // being set to a RouteAction_Cluster. RouteConfigClusterSpecifierTypeCluster RouteConfigClusterSpecifierType = iota // RouteConfigClusterSpecifierTypeWeightedCluster results in the cluster // specifier being set to RouteAction_WeightedClusters. RouteConfigClusterSpecifierTypeWeightedCluster // RouteConfigClusterSpecifierTypeClusterSpecifierPlugin results in the // cluster specifier being set to a RouteAction_ClusterSpecifierPlugin. RouteConfigClusterSpecifierTypeClusterSpecifierPlugin )
type RouteConfigOptions ¶ added in v1.54.0
type RouteConfigOptions struct { // RouteConfigName is the name of the RouteConfiguration resource. RouteConfigName string // ListenerName is the name of the Listener resource which uses this // RouteConfiguration. ListenerName string // ClusterSpecifierType determines the cluster specifier type. ClusterSpecifierType RouteConfigClusterSpecifierType // ClusterName is name of the cluster resource used when the cluster // specifier type is set to RouteConfigClusterSpecifierTypeCluster. // // Default value of "A" is used if left unspecified. ClusterName string // WeightedClusters is a map from cluster name to weights, and is used when // the cluster specifier type is set to // RouteConfigClusterSpecifierTypeWeightedCluster. // // Default value of {"A": 75, "B": 25} is used if left unspecified. WeightedClusters map[string]int // The below two fields specify the name of the cluster specifier plugin and // its configuration, and are used when the cluster specifier type is set to // RouteConfigClusterSpecifierTypeClusterSpecifierPlugin. Tests are expected // to provide valid values for these fields when appropriate. ClusterSpecifierPluginName string ClusterSpecifierPluginConfig *anypb.Any }
RouteConfigOptions contains options to configure a RouteConfiguration resource.
type SecurityLevel ¶
type SecurityLevel int
SecurityLevel allows the test to control the security level to be used in the resource returned by this package.
const ( // SecurityLevelNone is used when no security configuration is required. SecurityLevelNone SecurityLevel = iota // SecurityLevelTLS is used when security configuration corresponding to TLS // is required. Only the server presents an identity certificate in this // configuration. SecurityLevelTLS // SecurityLevelMTLS is used when security ocnfiguration corresponding to // mTLS is required. Both client and server present identity certificates in // this configuration. SecurityLevelMTLS )
type UpdateOptions ¶
type UpdateOptions struct { // NodeID is the id of the client to which this update is to be pushed. NodeID string // Endpoints, Clusters, Routes, and Listeners are the updated list of xds // resources for the server. All must be provided with each Update. Endpoints []*v3endpointpb.ClusterLoadAssignment Clusters []*v3clusterpb.Cluster Routes []*v3routepb.RouteConfiguration Listeners []*v3listenerpb.Listener // SkipValidation indicates whether we want to skip validation (by not // calling snapshot.Consistent()). It can be useful for negative tests, // where we send updates that the client will NACK. SkipValidation bool }
UpdateOptions wraps parameters to be passed to the Update() method.
func DefaultClientResources ¶
func DefaultClientResources(params ResourceParams) UpdateOptions
DefaultClientResources returns a set of resources (LDS, RDS, CDS, EDS) for a client to generically connect to one server.