xdsresource

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListenerTypeURL        = apiTypePrefix + "envoy.config.listener.v3.Listener"
	RouteTypeURL           = apiTypePrefix + "envoy.config.route.v3.RouteConfiguration"
	ClusterTypeURL         = apiTypePrefix + "envoy.config.cluster.v3.Cluster"
	EndpointTypeURL        = apiTypePrefix + "envoy.config.endpoint.v3.ClusterLoadAssignment"
	SecretTypeURL          = apiTypePrefix + "envoy.extensions.transport_sockets.tls.v3.Secret"
	ExtensionConfigTypeURL = apiTypePrefix + "envoy.config.core.v3.TypedExtensionConfig"
	RuntimeTypeURL         = apiTypePrefix + "envoy.service.runtime.v3.Runtime"
	HTTPConnManagerTypeURL = apiTypePrefix + "envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"
	ThriftProxyTypeURL     = apiTypePrefix + "envoy.extensions.filters.network.thrift_proxy.v3.ThriftProxy"

	NameTableTypeURL = apiTypePrefix + "istio.networking.nds.v1.NameTable"
	// AnyType is used only by ADS
	AnyType = ""
)

Resource types in xDS v3.

Variables

View Source
var (
	HostName1        = "host1"
	Port1            = "80"
	ClusterIP1       = "0.0.0.0"
	ListenerName1    = HostName1 + ":" + Port1
	ReturnedLisName1 = ClusterIP1 + "_" + Port1

	HostName2        = "host2"
	Port2            = "8080"
	ClusterIP2       = "10.0.0.1"
	ListenerName2    = HostName2 + ":" + Port2
	ReturnedLisName2 = ClusterIP2 + "_" + Port2
	ReturnedLisName3 = "lis3"

	Listener1 = &v3listenerpb.Listener{
		Name: ReturnedLisName1,
		FilterChains: []*v3listenerpb.FilterChain{
			{
				Filters: []*v3listenerpb.Filter{
					{
						ConfigType: &v3listenerpb.Filter_TypedConfig{
							TypedConfig: MarshalAny(httpConnectionManager1),
						},
					},
					{
						ConfigType: &v3listenerpb.Filter_TypedConfig{
							TypedConfig: MarshalAny(thriftProxy),
						},
					},
				},
			},
		},
	}

	Listener2 = &v3listenerpb.Listener{
		Name: ReturnedLisName2,
		FilterChains: []*v3listenerpb.FilterChain{
			{
				Filters: []*v3listenerpb.Filter{
					{
						ConfigType: &v3listenerpb.Filter_TypedConfig{
							TypedConfig: MarshalAny(httpConnectionManager2),
						},
					},
					{
						ConfigType: &v3listenerpb.Filter_TypedConfig{
							TypedConfig: MarshalAny(thriftProxy),
						},
					},
				},
			},
		},
		DefaultFilterChain: &v3listenerpb.FilterChain{
			Filters: []*v3listenerpb.Filter{
				{
					ConfigType: &v3listenerpb.Filter_TypedConfig{
						TypedConfig: MarshalAny(thriftProxy),
					},
				},
			},
		},
	}
	// Listener3 with thrift proxy in FilterChain and DefaultFilterChain
	Listener3 = &v3listenerpb.Listener{
		Name: ReturnedLisName3,
		FilterChains: []*v3listenerpb.FilterChain{
			{
				Filters: []*v3listenerpb.Filter{
					{
						ConfigType: &v3listenerpb.Filter_TypedConfig{
							TypedConfig: MarshalAny(thriftProxy),
						},
					},
				},
			},
		},
		DefaultFilterChain: &v3listenerpb.FilterChain{
			Filters: []*v3listenerpb.Filter{
				{
					ConfigType: &v3listenerpb.Filter_TypedConfig{
						TypedConfig: MarshalAny(thriftProxy),
					},
				},
			},
		},
	}
)
View Source
var (
	RouteConfigName1 = "routeConfig1"
	RouteConfigName2 = "routeConfig2"

	RouteConfig1 = &v3routepb.RouteConfiguration{
		Name: RouteConfigName1,
		VirtualHosts: []*v3routepb.VirtualHost{
			{
				Name: "vhName",
				Routes: []*v3routepb.Route{
					{
						Match: &v3routepb.RouteMatch{
							PathSpecifier: &v3routepb.RouteMatch_Path{
								Path: "path",
							},
						},
						Action: &v3routepb.Route_Route{
							Route: &v3routepb.RouteAction{
								ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
									WeightedClusters: &v3routepb.WeightedCluster{
										Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
											{
												Name: ClusterName1,
												Weight: &wrapperspb.UInt32Value{
													Value: uint32(50),
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	}
	RouteConfig2 = &v3routepb.RouteConfiguration{
		Name: RouteConfigName2,
		VirtualHosts: []*v3routepb.VirtualHost{
			{
				Name: "vhName",
				Routes: []*v3routepb.Route{
					{
						Match: &v3routepb.RouteMatch{
							PathSpecifier: &v3routepb.RouteMatch_Path{
								Path: "path",
							},
						},
						Action: &v3routepb.Route_Route{
							Route: &v3routepb.RouteAction{
								ClusterSpecifier: &v3routepb.RouteAction_WeightedClusters{
									WeightedClusters: &v3routepb.WeightedCluster{
										Clusters: []*v3routepb.WeightedCluster_ClusterWeight{
											{
												Name: ClusterName1,
												Weight: &wrapperspb.UInt32Value{
													Value: uint32(50),
												},
											},
										},
									},
								},
							},
						},
					},
				},
			},
		},
	}
)
View Source
var (
	ClusterName1 = "cluster1"
	ClusterName2 = "cluster2"

	Cluster1 = &v3clusterpb.Cluster{
		Name:                 ClusterName1,
		ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
		EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
			ServiceName: EndpointName1,
		},
		LbPolicy:       v3clusterpb.Cluster_ROUND_ROBIN,
		LoadAssignment: nil,
	}
	Cluster2 = &v3clusterpb.Cluster{
		Name:                 ClusterName2,
		ClusterDiscoveryType: &v3clusterpb.Cluster_Type{Type: v3clusterpb.Cluster_EDS},
		EdsClusterConfig: &v3clusterpb.Cluster_EdsClusterConfig{
			ServiceName: EndpointName1,
		},
		LbPolicy:       v3clusterpb.Cluster_ROUND_ROBIN,
		LoadAssignment: nil,
	}
)

Cluster Resource

View Source
var (
	EndpointName1 = "endpoint1"
	EndpointName2 = "endpoint2"

	Endpoints1 = &v3endpointpb.ClusterLoadAssignment{
		ClusterName: EndpointName1,
		Endpoints: []*v3endpointpb.LocalityLbEndpoints{
			{
				LbEndpoints: []*v3endpointpb.LbEndpoint{
					{
						HostIdentifier: &v3endpointpb.LbEndpoint_Endpoint{
							Endpoint: &v3endpointpb.Endpoint{
								Address: &v3.Address{
									Address: &v3.Address_SocketAddress{
										SocketAddress: &v3.SocketAddress{
											Protocol: v3.SocketAddress_TCP,
											Address:  edsAddr,
											PortSpecifier: &v3.SocketAddress_PortValue{
												PortValue: uint32(edsPort1),
											},
										},
									},
								},
							},
						},
						LoadBalancingWeight: &wrapperspb.UInt32Value{
							Value: uint32(edsWeight1),
						},
					},
					{
						HostIdentifier: &v3endpointpb.LbEndpoint_Endpoint{
							Endpoint: &v3endpointpb.Endpoint{
								Address: &v3.Address{
									Address: &v3.Address_SocketAddress{
										SocketAddress: &v3.SocketAddress{
											Protocol: v3.SocketAddress_TCP,
											Address:  edsAddr,
											PortSpecifier: &v3.SocketAddress_PortValue{
												PortValue: uint32(edsPort2),
											},
										},
									},
								},
							},
						},
						LoadBalancingWeight: &wrapperspb.UInt32Value{
							Value: uint32(edsWeight2),
						},
					},
				},
			},
		},
	}
	Endpoints2 = &v3endpointpb.ClusterLoadAssignment{
		ClusterName: EndpointName2,
	}
)
View Source
var NameTable1 = &dnsProto.NameTable{
	Table: map[string]*dnsProto.NameTable_NameInfo{
		HostName1: {
			Ips: []string{ClusterIP1},
		},
		HostName2: {
			Ips: []string{ClusterIP2},
		},
	},
}
View Source
var ResourceTypeToName = map[ResourceType]string{
	ListenerType:    "Listener",
	RouteConfigType: "RouteConfig",
	ClusterType:     "Cluster",
	EndpointsType:   "ClusterLoadAssignment",
	NameTableType:   "NameTable",
}

Functions

func MarshalAny

func MarshalAny(message proto.Message) *any.Any

func UnmarshalCDS

func UnmarshalCDS(rawResources []*any.Any) (map[string]Resource, error)

func UnmarshalEDS

func UnmarshalEDS(rawResources []*any.Any) (map[string]Resource, error)

func UnmarshalLDS

func UnmarshalLDS(rawResources []*any.Any) (map[string]*ListenerResource, error)

UnmarshalLDS unmarshalls the LDS Response. Only focus on OutboundListener now. Get the InlineRouteConfig or RouteConfigName from the listener.

func UnmarshalRDS

func UnmarshalRDS(rawResources []*any.Any) (map[string]Resource, error)

Types

type ClusterDiscoveryType

type ClusterDiscoveryType int
const (
	ClusterDiscoveryTypeEDS ClusterDiscoveryType = iota
	ClusterDiscoveryTypeLogicalDNS
	ClusterDiscoveryTypeStatic
)

func (ClusterDiscoveryType) String

func (d ClusterDiscoveryType) String() string

type ClusterLbPolicy

type ClusterLbPolicy int
const (
	ClusterLbRoundRobin ClusterLbPolicy = iota
	ClusterLbRingHash
)

func (ClusterLbPolicy) String

func (p ClusterLbPolicy) String() string

type ClusterResource

type ClusterResource struct {
	DiscoveryType   ClusterDiscoveryType
	LbPolicy        ClusterLbPolicy
	EndpointName    string
	InlineEndpoints *EndpointsResource
}

func (*ClusterResource) InlineEDS

func (c *ClusterResource) InlineEDS() *EndpointsResource

func (*ClusterResource) MarshalJSON

func (c *ClusterResource) MarshalJSON() ([]byte, error)

type Endpoint

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

func (*Endpoint) Addr

func (e *Endpoint) Addr() net.Addr

func (*Endpoint) MarshalJSON

func (e *Endpoint) MarshalJSON() ([]byte, error)

func (*Endpoint) Meta

func (e *Endpoint) Meta() map[string]string

func (*Endpoint) Tag

func (e *Endpoint) Tag(key string) (value string, exist bool)

func (*Endpoint) Weight

func (e *Endpoint) Weight() uint32

type EndpointsResource

type EndpointsResource struct {
	Localities []*Locality
}

type ExactMatcher added in v0.3.0

type ExactMatcher string

func (ExactMatcher) Match added in v0.3.0

func (em ExactMatcher) Match(other string) bool

type HTTPRouteConfig

type HTTPRouteConfig struct {
	VirtualHosts []*VirtualHost
}

type HTTPRouteMatch

type HTTPRouteMatch struct {
	Path    string
	Prefix  string
	Headers Matchers
}

func (*HTTPRouteMatch) MatchMeta added in v0.3.0

func (rm *HTTPRouteMatch) MatchMeta(md map[string]string) bool

func (*HTTPRouteMatch) MatchPath

func (rm *HTTPRouteMatch) MatchPath(path string) bool

type ListenerResource

type ListenerResource struct {
	NetworkFilters []*NetworkFilter
}

ListenerResource is the resource parsed from the lds response. Only includes NetworkFilters now

func (*ListenerResource) ResourceType added in v0.2.0

func (r *ListenerResource) ResourceType() ResourceType

type Locality

type Locality struct {
	Endpoints []*Endpoint
}

type Matcher added in v0.3.0

type Matcher interface {
	Match(string) bool
}

type Matchers added in v0.3.0

type Matchers map[string]Matcher

func BuildMatchers added in v0.3.0

func BuildMatchers(headers []*v3.HeaderMatcher) Matchers

BuildMatchers build matcher set from headers

func (Matchers) Match added in v0.3.0

func (ms Matchers) Match(other map[string]string) bool

type NDSResource

type NDSResource struct {
	NameTable map[string][]string
}

func UnmarshalNDS

func UnmarshalNDS(rawResources []*any.Any) (*NDSResource, error)

type NetworkFilter

type NetworkFilter struct {
	FilterType        NetworkFilterType
	RouteConfigName   string
	InlineRouteConfig *RouteConfigResource
}

NetworkFilter contains the network filter config we need got from Listener.FilterChains. Only support HttpConnectionManager and ThriftProxy. If InlineRouteConfig is not nil, use it to perform routing. Or, use RouteConfigName as the resourceName to get the RouteConfigResource.

type NetworkFilterType

type NetworkFilterType int
const (
	NetworkFilterTypeHTTP NetworkFilterType = iota
	NetworkFilterTypeThrift
)

type PrefixMatcher added in v0.3.0

type PrefixMatcher string

func (PrefixMatcher) Match added in v0.3.0

func (pm PrefixMatcher) Match(other string) bool

type RegexMatcher added in v0.3.0

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

func (*RegexMatcher) Match added in v0.3.0

func (rm *RegexMatcher) Match(other string) bool

type Resource

type Resource interface{}

type ResourceMeta

type ResourceMeta struct {
	Version        string
	UpdateTime     time.Time
	LastAccessTime atomic.Value
}

ResourceMeta records the meta information of a resource.

type ResourceType

type ResourceType int
const (
	UnknownResource ResourceType = iota
	ListenerType
	RouteConfigType
	ClusterType
	EndpointsType

	NameTableType
)

func (ResourceType) RequireFullADSResponse added in v0.2.0

func (rt ResourceType) RequireFullADSResponse() bool

RequireFullADSResponse returns if a full response is required for every update.

type Route

type Route struct {
	Match            RouteMatch
	WeightedClusters []*WeightedCluster
	Timeout          time.Duration
}

func (*Route) MarshalJSON

func (r *Route) MarshalJSON() ([]byte, error)

type RouteConfigResource

type RouteConfigResource struct {
	HTTPRouteConfig   *HTTPRouteConfig
	ThriftRouteConfig *ThriftRouteConfig
}

RouteConfigResource is used for routing HTTPRouteConfig is the native http route config, which consists of a list of virtual hosts. ThriftRouteConfig is converted from the routeConfiguration in thrift proxy, which can only be configured in the listener filter For details of thrift_proxy, please refer to: https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/network/thrift_proxy/v3/route.proto#envoy-v3-api-msg-extensions-filters-network-thrift-proxy-v3-routeconfiguration

type RouteMatch

type RouteMatch interface {
	MatchPath(path string) bool
	// default use headers to match the meta.
	MatchMeta(map[string]string) bool
}

type ThriftRouteConfig

type ThriftRouteConfig struct {
	Routes []*Route
}

type ThriftRouteMatch

type ThriftRouteMatch struct {
	Method      string
	ServiceName string
	Tags        Matchers
}

func (*ThriftRouteMatch) MatchMeta added in v0.3.0

func (tm *ThriftRouteMatch) MatchMeta(md map[string]string) bool

func (*ThriftRouteMatch) MatchPath

func (tm *ThriftRouteMatch) MatchPath(path string) bool

type VirtualHost

type VirtualHost struct {
	Name   string
	Routes []*Route
}

type WeightedCluster

type WeightedCluster struct {
	Name   string
	Weight uint32
}

Jump to

Keyboard shortcuts

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