Documentation ¶
Index ¶
- type EndpointAddress
- type EndpointStatus
- type Features
- type FixedHash
- type FixedLocalityPriority
- type GRPCApplication
- type GRPCApplicationCache
- type GRPCApplicationEndpoints
- type LocalityMatch
- type LocalityPriorityByZone
- type LocalityPriorityMapper
- type ServerListenerCache
- type SnapshotBuilder
- type SnapshotCache
- func (c *SnapshotCache) CreateDeltaWatch(request *cachev3.DeltaRequest, state stream.StreamState, ...) (cancel func())
- func (c *SnapshotCache) CreateWatch(request *cachev3.Request, state stream.StreamState, ...) (cancel func())
- func (c *SnapshotCache) Fetch(ctx context.Context, request *cachev3.Request) (cachev3.Response, error)
- func (c *SnapshotCache) UpdateResources(_ context.Context, logger logr.Logger, kubecontextName string, ...) error
- type ZoneHash
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EndpointAddress ¶
EndpointAddress represents a socket ipAddress, with an IP address (e.g., "0.0.0.0" or "[::]"), and a port.
type EndpointStatus ¶
type EndpointStatus int
EndpointStatus represents the serving status of an endpoint.
const ( Healthy EndpointStatus = iota Unhealthy Draining )
func EndpointStatusFromConditions ¶
func EndpointStatusFromConditions(c discoveryv1.EndpointConditions) EndpointStatus
func (EndpointStatus) HealthStatus ¶
func (e EndpointStatus) HealthStatus() corev3.HealthStatus
func (EndpointStatus) String ¶
func (e EndpointStatus) String() string
type Features ¶
type Features struct { ServerListenerUsesRDS bool `yaml:"serverListenerUsesRds"` EnableControlPlaneTLS bool `yaml:"enableControlPlaneTls"` RequireControlPlaneClientCerts bool `yaml:"requireControlPlaneClientCerts"` EnableDataPlaneTLS bool `yaml:"enableDataPlaneTls"` RequireDataPlaneClientCerts bool `yaml:"requireDataPlaneClientCerts"` EnableFederation bool `yaml:"enableFederation"` }
Features of the xDS control plane that can be enabled and disabled via a config file.
type FixedLocalityPriority ¶
type FixedLocalityPriority struct{}
FixedLocalityPriority returns an empty map. Lookups in the map will always return 0 as the value, so all localities can be assigned the highest priority.
func (FixedLocalityPriority) BuildPriorityMap ¶
func (f FixedLocalityPriority) BuildPriorityMap(_ string, _ []string) map[string]uint32
type GRPCApplication ¶
type GRPCApplication struct { Namespace string ServiceAccountName string ListenerName string RouteConfigurationName string ClusterName string EDSServiceName string PathPrefix string Port uint32 Endpoints []GRPCApplicationEndpoints }
func NewGRPCApplication ¶
func NewGRPCApplication(namespace string, name string, port uint32, endpoints []GRPCApplicationEndpoints) GRPCApplication
NewGRPCApplication is a convenience function that creates a GRPCApplication where the k8s ServiceAccount, LDS Listener, RDS RouteConfiguration, CDS Cluster, and EDS ServiceName all share the same name.
func (GRPCApplication) Compare ¶
func (a GRPCApplication) Compare(b GRPCApplication) int
Compare assumes that the list of endpoints is sorted, as done in `NewGRPCApplication()`.
func (GRPCApplication) Equal ¶
func (a GRPCApplication) Equal(b GRPCApplication) bool
Equal assumes that the list of endpoints is sorted, as done in `NewGRPCApplication()`.
type GRPCApplicationCache ¶
type GRPCApplicationCache struct {
// contains filtered or unexported fields
}
The GRPCApplicationCache key is `<kubecontext>/<namespace>`.
func NewGRPCApplicationCache ¶
func NewGRPCApplicationCache() *GRPCApplicationCache
func (*GRPCApplicationCache) Get ¶
func (c *GRPCApplicationCache) Get(kubecontextName string, namespace string) []GRPCApplication
func (*GRPCApplicationCache) GetAll ¶
func (c *GRPCApplicationCache) GetAll() []GRPCApplication
func (*GRPCApplicationCache) Put ¶
func (c *GRPCApplicationCache) Put(kubecontextName string, namespace string, apps []GRPCApplication) bool
Put returns true iff the update changed the cache. Use the return value to avoid sending xDS updates to clients when nothing has changed.
type GRPCApplicationEndpoints ¶
type GRPCApplicationEndpoints struct { Node string Zone string Addresses []string EndpointStatus EndpointStatus }
func NewGRPCApplicationEndpoints ¶
func NewGRPCApplicationEndpoints(node string, zone string, addresses []string, endpointStatus EndpointStatus) GRPCApplicationEndpoints
func (GRPCApplicationEndpoints) Compare ¶
func (e GRPCApplicationEndpoints) Compare(f GRPCApplicationEndpoints) int
Compare assumes that the list of addresses is sorted, as done in `NewGRPCApplicationEndpoints()`.
func (GRPCApplicationEndpoints) Equal ¶
func (e GRPCApplicationEndpoints) Equal(f GRPCApplicationEndpoints) bool
Equal assumes that the list of addresses is sorted, as done in `NewGRPCApplicationEndpoints()`.
type LocalityMatch ¶
type LocalityMatch int
LocalityMatch defines the priority order of matching or part-matching locality. In other words, the priority order is as follows:
- same zone
- same region
- same super-region
- same multi-region
- other
const ( Zone LocalityMatch = iota Region SuperRegion MultiRegion Other )
type LocalityPriorityByZone ¶
type LocalityPriorityByZone struct{}
LocalityPriorityByZone determines EDS ClusterLoadAssignment locality priorites, based on the zone of the requesting node.
Priorities start from 0 (highest), and must increase without any gaps. Multiple localities can share the same priority.
Zone and region are names of cloud provider locations, e.g., the `us-central1-f` zone, and the `us-central1` region.
Super-region is an invented term for this implementation. It is essentially the cloud provider region, excluding the numeric suffix. E.g., for the `us-west1` region, the super-region is `us-west`. This means that the `us-west1` and `us-west2` regions are in the same super-region. The intention is to provide a next level of priority, after considering zone and region. E.g., if traffic originates from `us-west1`, but no healthy endpoints are available in that region, we may prefer to send traffic to a nearby region, such as, e.g., `us-west2`, before considering other regions that are geographically more distant, e.g., `us-east1`.
Multi-region is an invented term for this implementation. It is essentially the first part of the cloud provider region name, up to the first hyphen (`-`). E.g., for the region `us-east1`, the multi-region is `us`. This means that the `us-west1` and `us-east1` regions are in the same multi-region. The intention is to provide a next level of priority, after considering zone, region, and super-region. E.g., if traffic originates from `us-west1`, but no healthy endpoints are available in any of the `us-west1*` regions, we may prefer to send traffic to another region on the same continent, such as, e.g., `us-east1`, before considering regions on other continents, e.g., `europe-west1`.
func (LocalityPriorityByZone) BuildPriorityMap ¶
func (l LocalityPriorityByZone) BuildPriorityMap(nodeZone string, zonesToPrioritize []string) map[string]uint32
BuildPriorityMap constructs the priority map for the provided zones, based on the zone of the requesting node. Assumption: The nodeHash value (the first argument) is the zone name of the requesting node.
type LocalityPriorityMapper ¶
type LocalityPriorityMapper interface { // BuildPriorityMap constructs the priority map for the provided zones, based on the node hash. BuildPriorityMap(nodeHash string, zones []string) map[string]uint32 }
LocalityPriorityMapper determines EDS ClusterLoadAssignment locality priorites.
type ServerListenerCache ¶
type ServerListenerCache struct {
// contains filtered or unexported fields
}
func NewServerListenerCache ¶
func NewServerListenerCache() *ServerListenerCache
func (*ServerListenerCache) Add ¶
func (c *ServerListenerCache) Add(nodeHash string, newAddresses []EndpointAddress) bool
Add returns true if at least one of the new server listener addresses did not already exist in the cache for the provided `nodeHash` cache key.
func (*ServerListenerCache) Get ¶
func (c *ServerListenerCache) Get(nodeHash string) []EndpointAddress
type SnapshotBuilder ¶
type SnapshotBuilder struct {
// contains filtered or unexported fields
}
SnapshotBuilder builds xDS resource snapshots for the cache.
func NewSnapshotBuilder ¶
func NewSnapshotBuilder(nodeHash string, localityPriorityMapper LocalityPriorityMapper, features *Features, authority string) *SnapshotBuilder
NewSnapshotBuilder initializes the builder.
func (*SnapshotBuilder) AddGRPCApplications ¶
func (b *SnapshotBuilder) AddGRPCApplications(apps []GRPCApplication) (*SnapshotBuilder, error)
AddGRPCApplications adds the provided application configurations to the xDS resource snapshot.
func (*SnapshotBuilder) AddServerListenerAddresses ¶
func (b *SnapshotBuilder) AddServerListenerAddresses(addresses []EndpointAddress) *SnapshotBuilder
AddServerListenerAddresses adds server listeners and associated route configurations with the provided IP addresses and ports to the snapshot.
func (*SnapshotBuilder) Build ¶
func (b *SnapshotBuilder) Build() (cachev3.ResourceSnapshot, error)
Build adds the server listeners and route configuration for the node hash, and then builds the snapshot.
type SnapshotCache ¶
type SnapshotCache struct {
// contains filtered or unexported fields
}
SnapshotCache stores snapshots of xDS resources in a delegate cache.
It handles server listener requests by intercepting Listener stream creation, see `CreateWatch()`. Server listeners addresses from these requests are kept in a map, keyed by the node hash, and with a set of addresses per node hash.
It also handles propagating snapshots to all node hashes in the cache.
func NewSnapshotCache ¶
func NewSnapshotCache(ctx context.Context, allowPartialRequests bool, hash cachev3.NodeHash, localityPriorityMapper LocalityPriorityMapper, features *Features, authority string) *SnapshotCache
NewSnapshotCache creates an xDS resource cache for the provided node hash function.
If `allowPartialRequests` is true, the DiscoveryServer will respond to requests for a resource type even if some resources in the snapshot are not named in the request.
func (*SnapshotCache) CreateDeltaWatch ¶
func (c *SnapshotCache) CreateDeltaWatch(request *cachev3.DeltaRequest, state stream.StreamState, responses chan cachev3.DeltaResponse) (cancel func())
CreateDeltaWatch just delegates, since gRPC does not support delta/incremental xDS currently. TODO: Handle request for gRPC server Listeners once gRPC implementation support delta/incremental xDS.
func (*SnapshotCache) CreateWatch ¶
func (c *SnapshotCache) CreateWatch(request *cachev3.Request, state stream.StreamState, responses chan cachev3.Response) (cancel func())
CreateWatch intercepts stream creation before delegating, and if it is a new Listener stream, does the following:
- Extracts addresses and ports of any server listeners in the request and adds them to the set of known server listener socket addresses for the node hash.
- If there is no existing snapshot, or if the request contained new and previously unseen server listener addresses the node hash, creates a new snapshot for that node hash, with the server listeners and associated route configuration.
This solves (in a slightly hacky way) bootstrapping of xDS-enabled gRPC servers.
func (*SnapshotCache) UpdateResources ¶
func (c *SnapshotCache) UpdateResources(_ context.Context, logger logr.Logger, kubecontextName string, namespace string, updatedApps []GRPCApplication) error
UpdateResources creates a new snapshot for each node hash in the cache, based on the provided gRPC application configuration, with the addition of server listeners and their associated route configurations.