v2

package
v0.0.0-...-730bba4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Package v2 is a port of package v1 from using the Envoy v1 API (JSON based) to v2 API (proto based).

Package v2 provides the adapters to convert Pilot's older data model objects to those required by envoy's v2 APIs. For Envoy terminology: https://www.envoyproxy.io/docs/envoy/latest/api-v2/api

This package is likely to be deprecated once v1 REST based APIs are obsoleted. Use with extreme caution.

Package v2 provides Mesh, Package v2 provides Mesh, a environment independent abstraction used to synchronize the list of endpoints used by Pilot with those watched by environment specific registries. It implements all the necessary logic that's used for service discovery based on routing rules and endpoint subsets. Typical Usage:

    import "istio.io/istio/pilot/model"

    type MyServiceRegistry struct {
      Mesh
    }
    ...
    mpr := MyServiceRegistry{model.NewMesh()}
    ...
    var allEndpoints []*model.ServiceInstances
    nativeEndpoints = buildYourServiceEndpointList()
    subsetEndpoints := make([]*Endpoint, 0, len(nativeEndpoints))
	   for _, nativeEp := range nativeEndpoints {
      // Create mesh endpoint from relevant values of nativeEp
	     subsetEndpoints = append(subsetEndpoints, NewEndpoint(......))
    }
    err := mpr.Reconcile(subsetEndpoints)

Internally xDS will use the following interfaces for: (Service-)Cluster Discovery Service:

serviceClusters := mesh.SubsetNames()

Endpoint Discovery Service:

var listOfSubsets []string{}
listOfSubsets := somePkg.FigureOutSubsetsToQuery()
subsetEndpoints := mesh.SubsetEndpoints(listOfSubsets)

Internally Galley will use the following interfaces for updating Pilot configuration:

var routeRuleChanges []RuleChange
routeRuleChanges := somePkg.FigureOutRouteRuleChanges()
err := mesh.UpdateRules(routeRuleChanges)

Index

Constants

View Source
const (
	HeaderMethod    = ":method"
	HeaderAuthority = ":authority"
	HeaderScheme    = ":scheme"
)

Headers with special meaning in Envoy

View Source
const (
	// UnresolvedCluster for destinations pointing to unknown clusters.
	UnresolvedCluster = "unresolved-cluster"

	// DefaultOperation is the default decorator
	DefaultOperation = "default-operation"
)
View Source
const (

	// RuleSubsetSeparator separates the destination rule name and the subset name for
	// the key to the subsetEndpoints map.
	RuleSubsetSeparator = "|"
)

Variables

This section is empty.

Functions

func EndpointFromInstance

func EndpointFromInstance(instance *model.ServiceInstance) (*endpoint.LbEndpoint, error)

EndpointFromInstance returns an Envoy v2 Endpoint from Pilot's older data structure model.ServiceInstance.

func Endpoints

func Endpoints(ds *v1.DiscoveryService, serviceClusters []string) *xdsapi.DiscoveryResponse

Endpoints implements MeshDiscovery.Endpoints()

func ListListenersResponse

func ListListenersResponse(env model.Environment, node model.Proxy) (*xdsapi.DiscoveryResponse, error)

ListListenersResponse returns a list of listeners for the given environment and source node.

func LocalityLbEndpointsFromInstances

func LocalityLbEndpointsFromInstances(instances []*model.ServiceInstance) []endpoint.LocalityLbEndpoints

LocalityLbEndpointsFromInstances returns a list of Envoy v2 LocalityLbEndpoints and a total count of Envoy v2 Endpoints constructed from Pilot's older data structure involving model.ServiceInstance objects.

func MatchServiceHosts

func MatchServiceHosts(in model.Config, serviceByName ServiceByName) ([]string, []*model.Service)

MatchServiceHosts splits the virtual service hosts into services and literal hosts

func TranslateBool

func TranslateBool(in *wrappers.BoolValue) *types.BoolValue

TranslateBool converts bool wrapper.

func TranslateCORSPolicy

func TranslateCORSPolicy(in *networking.CorsPolicy) *route.CorsPolicy

TranslateCORSPolicy translates CORS policy

func TranslateHeaderMatcher

func TranslateHeaderMatcher(name string, in *networking.StringMatch) route.HeaderMatcher

TranslateHeaderMatcher translates to HeaderMatcher

func TranslateRetryPolicy

func TranslateRetryPolicy(in *networking.HTTPRetry) *route.RouteAction_RetryPolicy

TranslateRetryPolicy translates retry policy

func TranslateRouteMatch

func TranslateRouteMatch(in *networking.HTTPMatchRequest) route.RouteMatch

TranslateRouteMatch translates match condition

func TranslateTime

func TranslateTime(in *duration.Duration) *time.Duration

TranslateTime converts time protos.

Types

type ClusterNaming

type ClusterNaming func(*networking.Destination) string

ClusterNaming specifies cluster name for a destination

func TranslateDestination

func TranslateDestination(
	serviceByName ServiceByName,
	subsetSelector SubsetSelector,
	contextNamespace string,
	defaultPort int) ClusterNaming

TranslateDestination produces a cluster naming function using the config context.

type ConfigCache

type ConfigCache struct {
	// contains filtered or unexported fields
}

ConfigCache for xDS resources

func NewConfigCache

func NewConfigCache(services model.ServiceDiscovery, configs model.ConfigStore) *ConfigCache

NewConfigCache spins up a new config cache

func (*ConfigCache) ID

func (cache *ConfigCache) ID(node *core.Node) string

ID ...

func (*ConfigCache) OnConfigEvent

func (cache *ConfigCache) OnConfigEvent(svc model.Config, event model.Event)

OnConfigEvent ...

func (*ConfigCache) OnFetchRequest

func (cache *ConfigCache) OnFetchRequest(*v2.DiscoveryRequest)

OnFetchRequest ...

func (*ConfigCache) OnFetchResponse

func (cache *ConfigCache) OnFetchResponse(*v2.DiscoveryRequest, *v2.DiscoveryResponse)

OnFetchResponse ...

func (*ConfigCache) OnServiceEvent

func (cache *ConfigCache) OnServiceEvent(svc *model.Service, event model.Event)

OnServiceEvent ...

func (*ConfigCache) OnStreamClosed

func (cache *ConfigCache) OnStreamClosed(int64)

OnStreamClosed ...

func (*ConfigCache) OnStreamOpen

func (cache *ConfigCache) OnStreamOpen(int64, string)

OnStreamOpen ...

func (*ConfigCache) OnStreamRequest

func (cache *ConfigCache) OnStreamRequest(int64, *v2.DiscoveryRequest)

OnStreamRequest ...

func (*ConfigCache) OnStreamResponse

func (cache *ConfigCache) OnStreamResponse(int64, *v2.DiscoveryRequest, *v2.DiscoveryResponse)

OnStreamResponse ...

func (*ConfigCache) Register

func (cache *ConfigCache) Register(grpcServer *grpc.Server)

Register with gRPC server

func (*ConfigCache) RegisterInput

func (cache *ConfigCache) RegisterInput(services model.Controller, configs model.ConfigStoreCache)

RegisterInput connects with the controllers

type ConfigChangeType

type ConfigChangeType int

ConfigChangeType is an enumeration for config changes, i.e add, update, delete

const (
	ConfigAdd ConfigChangeType = iota
	ConfigUpdate
	ConfigDelete
)

Enumerated constants for ConfigChangeType to indicate that the associated config data is being added, updated or deleted. The association implicitly expects the associated config data to furnish some form of unique identification so that this configuration element is updated independently of all other configuration elements within Pilot.

type DestinationAttribute

type DestinationAttribute string

DestinationAttribute encapsulates enums for key Istio attribute names used in Subsets and Endpoints

const (
	// DestinationUID is the attribute name for Mesh unique, environment-specific
	// unique identifier for the server instance of the destination service. Mesh
	// uses the label to uqniquely identify the endpoint when it receives updates
	// from the service registry. Example: kubernetes://my-svc-234443-5sffe.my-namespace
	// No two instances running anywhere in Mesh can have the same value for
	// UID.
	DestinationUID DestinationAttribute = "destination.uid"

	// DestinationService represents the fully qualified name of the service that the server
	// belongs to. Example: "my-svc.my-namespace.svc.cluster.local"
	DestinationService DestinationAttribute = "destination.service"

	// DestinationName represents the short name of the service that the server
	// belongs to. Example: "my-svc"
	DestinationName DestinationAttribute = "destination.name"

	// DestinationNamespace represents the namespace of the service. Example: "default"
	DestinationNamespace DestinationAttribute = "destination.namespace"

	// DestinationDomain represents the domain portion of the service name, excluding
	// the name and namespace, example: svc.cluster.local
	DestinationDomain DestinationAttribute = "destination.domain"

	// DestinationIP represents the IP address of the server instance, example 10.0.0.104.
	// This IP is expected to be reachable from Pilot. No distinction
	// is being made for directly reachable service instances versus those
	// behind a VIP. Istio's health discovery service will ensure that this
	// endpoint's capacity is correctly reported accordingly.
	DestinationIP DestinationAttribute = "destination.ip"

	// DestinationPort represents the recipient port on the server IP address, Example: 443
	DestinationPort DestinationAttribute = "destination.port"

	// DestinationUser represents the user running the destination application, example:
	// my-workload-identity
	DestinationUser DestinationAttribute = "destination.user"

	// DestinationProtocol represents the protocol of the connection being proxied, example:
	// grpc
	DestinationProtocol DestinationAttribute = "context.protocol"
)

func (DestinationAttribute) AttrName

func (attr DestinationAttribute) AttrName() string

AttrName returns the string value of attr.

type DestinationRuleType

type DestinationRuleType int

DestinationRuleType is an enumeration for how route.DestinationRule.Name should be interpreted, i.e. service domain, short name, CIDR, etc... TODO: move all DestinationAttributes to github.com/istio.io/api Key Istio attribute names for mapping endpoints to subsets. For details, please see https://istio.io/docs/reference/config/mixer/attribute-vocabulary.html

const (
	// DestinationRuleService is a type of destination rule where the
	// rule name is an FQDN of the service and resulting Subsets ought
	// to be further scoped to this FQDN.
	DestinationRuleService DestinationRuleType = iota

	// DestinationRuleName is a type of destination rule where
	// the rule name is the short name of the service and the
	// resulting subset ought to be further scoped to only those
	// Endpoints whose short service name match this short name.
	DestinationRuleName

	// DestinationRuleIP is a type of destination rule where
	// the rule name is a specific IP and the resulting subset
	// ought to be further scoped to this Endpoint's IP to determine
	// the Subset.
	DestinationRuleIP

	// DestinationRuleWildcard is a type of destination rule where
	// the rule name is a wild card domain name and the
	// resulting subset ought to be further scoped to only those
	// Endpoints whose domains match this wild card domain.
	DestinationRuleWildcard

	// DestinationRuleCIDR is a type of destination rule where
	// the rule name is a CIDR and the resulting subset
	// ought to be further scoped to only those Endpoints whose
	// IPs that match this CIDR.
	DestinationRuleCIDR
)

Enumerated constants for DestinationRuleType based on how route.DestinationRule.Name should be interpreted. TODO: Move DestinationRuleType to github.com/istio.io/api

type DiscoveryServer

type DiscoveryServer struct {

	// GrpcServer supports gRPC for xDS v2 services.
	GrpcServer *grpc.Server

	Connections map[string]*EdsConnection
	// contains filtered or unexported fields
}

DiscoveryServer is Pilot's gRPC implementation for Envoy's v2 xds APIs

func NewDiscoveryServer

func NewDiscoveryServer(mesh *v1.DiscoveryService, grpcServer *grpc.Server, env model.Environment) *DiscoveryServer

NewDiscoveryServer creates DiscoveryServer that sources data from Pilot's internal mesh data structures

func (*DiscoveryServer) FetchEndpoints

FetchEndpoints implements xdsapi.EndpointDiscoveryServiceServer.FetchEndpoints().

func (*DiscoveryServer) FetchListeners

FetchListeners implements the DiscoveryServer interface.

func (*DiscoveryServer) StreamEndpoints

StreamEndpoints implements xdsapi.EndpointDiscoveryServiceServer.StreamEndpoints().

func (*DiscoveryServer) StreamListeners

StreamListeners implements the DiscoveryServer interface.

func (*DiscoveryServer) StreamLoadStats

StreamLoadStats implements xdsapi.EndpointDiscoveryServiceServer.StreamLoadStats().

type EdsConnection

type EdsConnection struct {
}

EdsConnection represents a streaming connection from an envoy server

type Endpoint

type Endpoint endpoint.LbEndpoint

Endpoint is a environment independent representation of a Mesh Endpoints that uses Envoy v2 API's LbEndpoint as its internal implementation. It also provides utility methods intended for environment specific service registries.

func NewEndpoint

func NewEndpoint(address string, port uint32, socketProtocol SocketProtocol, labels []EndpointLabel) (*Endpoint, error)

NewEndpoint is a boiler-plate function intended for environment specific registries to create a new Endpoint. This method ensures all the necessary data required for creating subsets are correctly setup. It also performs sorting of arrays etc, to allow stable results for reflect.DeepEquals() for quick comparisons. The network address of the endpoint must be accessible from Pilot. If the registry creating the endpoint is for a remote Pilot, the endpoint's address may be that of an Istio gateway which must be accessible from Pilot. The gateway, itself, may have more than one Endpoints behind it that are not directly network accessible from Pilot. Similarly the the network port of this endpoint that must be accessible from Pilot. socketProtocol should be set to TCP or UPD. Labels are properties of the workload, for example: pod labels in Kubernetes.

type EndpointChange

type EndpointChange struct {
	// Endpoint the endpoint being added, deleted or updated
	Endpoint *endpoint.Endpoint
	// Type of config change
	Type ConfigChangeType
}

EndpointChange is intended for incremental updates from service registries

type EndpointLabel

type EndpointLabel struct {
	Name  string
	Value string
}

EndpointLabel is intended for registry provided labels on Endpoints.

type GuardedHost

type GuardedHost struct {
	// Port is the capture port (e.g. service port)
	Port int

	// Services are the services matching the virtual host.
	// The service host names need to be contextualized by the source.
	Services []*model.Service

	// Hosts is a list of alternative literal host names for the host.
	Hosts []string

	// Routes in the virtual host
	Routes []GuardedRoute
}

GuardedHost is a context-dependent virtual host entry with guarded routes.

func TranslateVirtualHost

func TranslateVirtualHost(in model.Config, serviceByName ServiceByName, subsetSelector SubsetSelector) []GuardedHost

TranslateVirtualHost creates virtual hosts corresponding to a virtual service.

func TranslateVirtualHosts

func TranslateVirtualHosts(
	serviceConfigs []model.Config,
	services map[string]*model.Service,
	subsetSelector SubsetSelector,
	clusterDomain string) []GuardedHost

TranslateVirtualHosts creates the entire routing table for Istio v1alpha2 configs. Services are indexed by FQDN hostnames. Cluster domain is used to resolve short service names (e.g. "svc.cluster.local").

type GuardedRoute

type GuardedRoute struct {
	route.Route

	// SourceLabels guarding the route
	SourceLabels map[string]string

	// Gateways pre-condition
	Gateways []string
}

GuardedRoute are routes for a destination guarded by deployment conditions.

func TranslateRoute

func TranslateRoute(in *networking.HTTPRoute,
	match *networking.HTTPMatchRequest,
	operation string,
	name ClusterNaming) GuardedRoute

TranslateRoute translates HTTP routes TODO: fault filters -- issue https://github.com/istio/api/issues/388

func TranslateRoutes

func TranslateRoutes(in model.Config, name ClusterNaming) []GuardedRoute

TranslateRoutes creates virtual host routes from the v1alpha2 config. The rule should be adapted to destination names (outbound clusters). Each rule is guarded by source labels.

type Mesh

type Mesh struct {
	// contains filtered or unexported fields
}

Mesh is a environment independent abstraction used by service registries for maintaining a list of service endpoints used by this Pilot.

Service registries under pilot/pkg/serviceregistry update the list of service endpoints in this Mesh with those available in a environment specific service registry.

Under the hoods, Mesh implements the necessary logic required for endpoint discovery based on routing rules and endpoint subsets. See https://github.com/istio/api/search?q=in%3Afile+"message+Subset"+language%3Aproto This logic includes comparing the updated list provided by Controllers with what this view holds and accordingly updating internal structures used for endpoint discovery.

func NewMesh

func NewMesh() *Mesh

NewMesh creates a new empty Mesh for use by Controller implementations

func (*Mesh) Reconcile

func (m *Mesh) Reconcile(endpoints []*Endpoint) error

Reconcile is intended to be called by individual service registries to update Mesh with the latest list of endpoints that make up the view into it's associated service registry. There should be only one thread calling Reconcile and the endpoints passed to Reconcile must represent the complete set of endpoints retrieved for that environment's service registry. The supplied endpoints should only have been created via NewEndpoint()

func (*Mesh) ReconcileDeltas

func (m *Mesh) ReconcileDeltas(endpointChanges []EndpointChange) error

ReconcileDeltas allows registies to update Meshes incrementally with only those Endpoints that have changed. TODO: Needs implementation.

func (*Mesh) SubsetEndpoints

func (m *Mesh) SubsetEndpoints(subsetNames []string) []*Endpoint

SubsetEndpoints implements functionality required for EDS and returns a list of endpoints that match one or more subsets.

func (*Mesh) SubsetNames

func (m *Mesh) SubsetNames() []string

SubsetNames implements functionality required for CDS and returns a list of all subset names currently configured for this Mesh

func (*Mesh) UpdateRules

func (m *Mesh) UpdateRules(ruleChanges []RuleChange) error

UpdateRules updates Mesh with changes to DestinationRules affecting Mesh. It updates Mesh for supplied events, adding, updating and deleting destination rules from this mesh depending on the corresponding ruleChange.Type.

type MeshDiscovery

type MeshDiscovery interface {
	// Endpoints implements EDS and returns a list of endpoints by subset for the list of supplied subsets.
	// In Envoy's terminology a subset is service cluster.
	Endpoints(serviceClusters []string) *xdsapi.DiscoveryResponse
}

MeshDiscovery is a unified interface for Envoy's v2 xDS APIs and Pilot's older data structure model. For Envoy terminology: https://www.envoyproxy.io/docs/envoy/latest/api-v2/api For Pilot older data structure model: istio.io/pilot/pkg/model

Implementations of MeshDiscovery are required to be threadsafe.

type RuleChange

type RuleChange struct {
	// Rule routing/v1alpha2/destination_rule.proto
	Rule *networking.DestinationRule
	// Type of destination rule config change
	Type ConfigChangeType
}

RuleChange encapsulates changes to Route Destination Rules

type ServiceByName

type ServiceByName func(host string, contextNamespace string) *model.Service

ServiceByName claims a service entry from the registry using a host name.

func TranslateServiceHostname

func TranslateServiceHostname(services map[string]*model.Service, clusterDomain string) ServiceByName

TranslateServiceHostname matches a host against a model service. This cannot be externalized to core model until the registries understand namespaces.

type SocketProtocol

type SocketProtocol int

SocketProtocol identifies the type of IP protocol, i.e. TCP/UDP

const (
	SocketProtocolTCP SocketProtocol = iota
	SocketProtocolUDP
)

Enumerated constants for SocketProtocol that's coupled with the internal implementation xdsapi.LbEndpoint

type SubsetSelector

type SubsetSelector func(service *model.Service, subset string) map[string]string

SubsetSelector resolves a subset to labels.

Jump to

Keyboard shortcuts

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