resource

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PassthroughClusterName  = "PassthroughCluster"
	RouteConfigName         = "polaris-router"
	OutBoundRouteConfigName = "polaris-outbound-router"
	InBoundRouteConfigName  = "polaris-inbound-cluster"
)
View Source
const (
	// LocalRateLimitStage envoy local ratelimit stage
	LocalRateLimitStage = 0
	// DistributedRateLimitStage envoy remote ratelimit stage
	DistributedRateLimitStage = 1
)
View Source
const (
	K8sDnsResolveSuffixSvc             = ".svc"
	K8sDnsResolveSuffixSvcCluster      = ".svc.cluster"
	K8sDnsResolveSuffixSvcClusterLocal = ".svc.cluster.local"
)
View Source
const (

	// GatewayNamespaceName xds metadata key when node is run in gateway mode
	GatewayNamespaceName = "gateway.polarismesh.cn/serviceNamespace"
	// GatewayNamespaceName xds metadata key when node is run in gateway mode
	GatewayServiceName = "gateway.polarismesh.cn/serviceName"
	// OldGatewayNamespaceName xds metadata key when node is run in gateway mode
	OldGatewayNamespaceName = "gateway_namespace"
	// OldGatewayServiceName xds metadata key when node is run in gateway mode
	OldGatewayServiceName = "gateway_service"
	// SidecarServiceName xds metadata key when node is run in sidecar mode
	SidecarServiceName = "sidecar.polarismesh.cn/serviceName"
	// SidecarNamespaceName xds metadata key when node is run in sidecar mode
	SidecarNamespaceName = "sidecar.polarismesh.cn/serviceNamespace"
	// SidecarBindPort xds metadata key when node is run in sidecar mode
	SidecarBindPort = "sidecar.polarismesh.cn/bindPorts"
)
View Source
const (
	// 这个是特殊指定的 prefix
	MatchString_Prefix = apimodel.MatchString_MatchStringType(-1)
)

Variables

View Source
var DefaultSdsConfig = &core.ConfigSource{
	ConfigSourceSpecifier: &core.ConfigSource_ApiConfigSource{
		ApiConfigSource: &core.ApiConfigSource{
			ApiType:             core.ApiConfigSource_GRPC,
			TransportApiVersion: core.ApiVersion_V3,
			GrpcServices: []*core.GrpcService{
				{
					TargetSpecifier: &core.GrpcService_EnvoyGrpc_{
						EnvoyGrpc: &core.GrpcService_EnvoyGrpc{
							ClusterName: "sds-grpc",
						},
					},
				},
			},
			SetNodeOnFirstMessageOnly: true,
		},
	},
	InitialFetchTimeout: &duration.Duration{},
	ResourceApiVersion:  core.ApiVersion_V3,
}
View Source
var InboundCommonTLSContext = &tlstrans.CommonTlsContext{
	TlsParams: &tlstrans.TlsParameters{
		TlsMinimumProtocolVersion: tlstrans.TlsParameters_TLSv1_2,
		CipherSuites: []string{
			"ECDHE-ECDSA-AES256-GCM-SHA384",
			"ECDHE-RSA-AES256-GCM-SHA384",
			"ECDHE-ECDSA-AES128-GCM-SHA256",
			"ECDHE-RSA-AES128-GCM-SHA256",
			"AES256-GCM-SHA384",
			"AES128-GCM-SHA256",
		},
	},
	TlsCertificateSdsSecretConfigs: []*tlstrans.SdsSecretConfig{
		{
			Name:      "default",
			SdsConfig: DefaultSdsConfig,
		},
	},
	ValidationContextType: &tlstrans.CommonTlsContext_CombinedValidationContext{
		CombinedValidationContext: &tlstrans.CommonTlsContext_CombinedCertificateValidationContext{
			DefaultValidationContext: &tlstrans.CertificateValidationContext{
				MatchSubjectAltNames: []*matcherv3.StringMatcher{
					{
						MatchPattern: &matcherv3.StringMatcher_Prefix{
							Prefix: "spiffe://cluster.local/",
						},
					},
				},
			},
			ValidationContextSdsSecretConfig: &tlstrans.SdsSecretConfig{
				Name:      "ROOTCA",
				SdsConfig: DefaultSdsConfig,
			},
		},
	},
}
View Source
var MTLSTransportSocketMatch = &structpb.Struct{
	Fields: map[string]*structpb.Value{
		"acceptMTLS": {Kind: &structpb.Value_StringValue{StringValue: "true"}},
	},
}
View Source
var OutboundCommonTLSContext = &tlstrans.CommonTlsContext{
	TlsCertificateSdsSecretConfigs: []*tlstrans.SdsSecretConfig{
		{
			Name:      "default",
			SdsConfig: DefaultSdsConfig,
		},
	},
	ValidationContextType: &tlstrans.CommonTlsContext_CombinedValidationContext{
		CombinedValidationContext: &tlstrans.CommonTlsContext_CombinedCertificateValidationContext{
			DefaultValidationContext: &tlstrans.CertificateValidationContext{},
			ValidationContextSdsSecretConfig: &tlstrans.SdsSecretConfig{
				Name:      "ROOTCA",
				SdsConfig: DefaultSdsConfig,
			},
		},
	},
}
View Source
var PassthroughCluster = &cluster.Cluster{
	Name:                 PassthroughClusterName,
	ConnectTimeout:       durationpb.New(5 * time.Second),
	ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_ORIGINAL_DST},
	LbPolicy:             cluster.Cluster_CLUSTER_PROVIDED,
	CircuitBreakers: &cluster.CircuitBreakers{
		Thresholds: []*cluster.CircuitBreakers_Thresholds{
			{
				MaxConnections:     &wrappers.UInt32Value{Value: math.MaxUint32},
				MaxPendingRequests: &wrappers.UInt32Value{Value: math.MaxUint32},
				MaxRequests:        &wrappers.UInt32Value{Value: math.MaxUint32},
				MaxRetries:         &wrappers.UInt32Value{Value: math.MaxUint32},
			},
		},
	},
}

Functions

func BuildAllowAnyVHost

func BuildAllowAnyVHost() *route.VirtualHost

func BuildCommonRouteMatch

func BuildCommonRouteMatch(routeMatch *route.RouteMatch, source *traffic_manage.SourceService)

func BuildRateLimitActionHeaderValueMatch

func BuildRateLimitActionHeaderValueMatch(key string,
	value *apimodel.MatchString) *route.RateLimit_Action_HeaderValueMatch

func BuildRateLimitConf

func BuildRateLimitConf(prefix string) *lrl.LocalRateLimit

func BuildSidecarRouteMatch

func BuildSidecarRouteMatch(routeMatch *route.RouteMatch, source *traffic_manage.SourceService)

func BuildWeightClustersV2

func BuildWeightClustersV2(trafficDirection corev3.TrafficDirection,
	destinations []*traffic_manage.DestinationGroup) *route.WeightedCluster

func DumpSnapShot

func DumpSnapShot(snapshot cache.ResourceSnapshot) []byte

func DumpSnapShotJSON

func DumpSnapShotJSON(snapshot cache.ResourceSnapshot) []byte

func FilterInboundRouterRule

func FilterInboundRouterRule(svc *ServiceInfo) []*traffic_manage.SubRuleRouting

func FormatEndpointHealth

func FormatEndpointHealth(ins *apiservice.Instance) core.HealthStatus

func GenEndpointMetaFromPolarisIns

func GenEndpointMetaFromPolarisIns(ins *apiservice.Instance) *core.Metadata

func GenerateServiceDomains

func GenerateServiceDomains(serviceInfo *ServiceInfo) []string

func IsNormalEndpoint

func IsNormalEndpoint(ins *apiservice.Instance) bool

func MakeDefaultFilterChain

func MakeDefaultFilterChain() *listenerv3.FilterChain

func MakeDefaultRoute

func MakeDefaultRoute(trafficDirection corev3.TrafficDirection, svcKey model.ServiceKey) *route.Route

默认路由

func MakeGatewayBoundHCM

func MakeGatewayBoundHCM() *hcm.HttpConnectionManager

func MakeGatewayLocalRateLimit

func MakeGatewayLocalRateLimit(rateLimitCache types.RateLimitCache, pathSpecifier string,
	svcKey model.ServiceKey) ([]*route.RateLimit, map[string]*anypb.Any, error)

func MakeGatewayRoute

func MakeGatewayRoute(trafficDirection corev3.TrafficDirection, routeMatch *route.RouteMatch,
	destinations []*traffic_manage.DestinationGroup) *route.Route

func MakeHealthCheck

func MakeHealthCheck(serviceInfo *ServiceInfo) []*core.HealthCheck

Translate the FaultDetector configuration of Polaris into HealthCheck

func MakeLbSubsetConfig

func MakeLbSubsetConfig(serviceInfo *ServiceInfo) *cluster.Cluster_LbSubsetConfig

func MakeOutlierDetection

func MakeOutlierDetection(serviceInfo *ServiceInfo) *cluster.OutlierDetection

Translate the circuit breaker configuration of Polaris into OutlierDetection

func MakeServiceGatewayDomains

func MakeServiceGatewayDomains() []string

func MakeServiceName

func MakeServiceName(svcKey model.ServiceKey, trafficDirection corev3.TrafficDirection) string

func MakeSidecarBoundHCM

func MakeSidecarBoundHCM(svcKey model.ServiceKey,
	trafficDirection corev3.TrafficDirection) *hcm.HttpConnectionManager

func MakeSidecarLocalRateLimit

func MakeSidecarLocalRateLimit(rateLimitCache types.RateLimitCache,
	svcKey model.ServiceKey) ([]*route.RateLimit, map[string]*anypb.Any, error)

func MakeSidecarRoute

func MakeSidecarRoute(trafficDirection corev3.TrafficDirection, routeMatch *route.RouteMatch,
	svcInfo *ServiceInfo, destinations []*traffic_manage.DestinationGroup) *route.Route

func MakeTLSTransportSocket

func MakeTLSTransportSocket(ctx proto.Message) *core.TransportSocket

func MustNewAny

func MustNewAny(src proto.Message) *anypb.Any

func ParseNodeID

func ParseNodeID(nodeID string) (runType, polarisNamespace, uuid, hostIP string)

func RegisterFactory

func RegisterFactory(xdsType XDSType, factory func() XDSBuilder)

RegisterFactory

func ToJSONArray

func ToJSONArray(resources map[string]types.Resource) []json.RawMessage

func YamlEncode

func YamlEncode(any interface{}) []byte

Types

type BuildOption

type BuildOption struct {
	Namespace    string
	TLSMode      TLSMode
	Services     map[model.ServiceKey]*ServiceInfo
	VersionLocal string
}

func (*BuildOption) Clone

func (opt *BuildOption) Clone() *BuildOption

type Callbacks

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

func NewCallback

func NewCallback(log *commonlog.Scope, nodeMgr *XDSNodeManager) *Callbacks

func (*Callbacks) OnDeltaStreamClosed

func (cb *Callbacks) OnDeltaStreamClosed(id int64, node *corev3.Node)

func (*Callbacks) OnDeltaStreamOpen

func (cb *Callbacks) OnDeltaStreamOpen(_ context.Context, id int64, typ string) error

func (*Callbacks) OnFetchRequest

func (cb *Callbacks) OnFetchRequest(_ context.Context, req *discovery.DiscoveryRequest) error

func (*Callbacks) OnFetchResponse

func (cb *Callbacks) OnFetchResponse(req *discovery.DiscoveryRequest, resp *discovery.DiscoveryResponse)

func (*Callbacks) OnStreamClosed

func (cb *Callbacks) OnStreamClosed(id int64, node *corev3.Node)

func (*Callbacks) OnStreamDeltaRequest

func (cb *Callbacks) OnStreamDeltaRequest(id int64, req *discovery.DeltaDiscoveryRequest) error

func (*Callbacks) OnStreamDeltaResponse

func (cb *Callbacks) OnStreamDeltaResponse(id int64, req *discovery.DeltaDiscoveryRequest,
	resp *discovery.DeltaDiscoveryResponse)

func (*Callbacks) OnStreamOpen

func (cb *Callbacks) OnStreamOpen(_ context.Context, id int64, typ string) error

func (*Callbacks) OnStreamRequest

func (cb *Callbacks) OnStreamRequest(id int64, req *discovery.DiscoveryRequest) error

func (*Callbacks) OnStreamResponse

func (cb *Callbacks) OnStreamResponse(_ context.Context, id int64, req *discovery.DiscoveryRequest,
	resp *discovery.DiscoveryResponse)

func (*Callbacks) Report

func (cb *Callbacks) Report()

type PolarisNodeHash

type PolarisNodeHash struct {
	NodeMgr *XDSNodeManager
}

PolarisNodeHash 存放 hash 方法

func (PolarisNodeHash) ID

func (PolarisNodeHash) ID(node *core.Node) string

ID id 的格式是 ${sidecar|gateway}~namespace/uuid~hostIp case 1: envoy 为 sidecar 模式时,则 NodeID 的格式为以下两种

	eg 1. namespace/uuid~hostIp
	eg 2. sidecar~namespace/uuid-hostIp
 eg 3. envoy_node_id="${NAMESPACE}/${INSTANCE_IP}~${POD_NAME}"

case 2: envoy 为 gateway 模式时,则 NodeID 的格式为: gateway~namespace/uuid~hostIp

type RunType

type RunType string
var (
	// RunTypeGateway xds node run type is gateway
	RunTypeGateway RunType = "gateway"
	// RunTypeSidecar xds node run type is sidecar
	RunTypeSidecar RunType = "sidecar"
)

type ServiceInfo

type ServiceInfo struct {
	ID                     string
	Name                   string
	Namespace              string
	ServiceKey             model.ServiceKey
	AliasFor               *model.Service
	Instances              []*apiservice.Instance
	SvcInsRevision         string
	Routing                *traffic_manage.Routing
	SvcRoutingRevision     string
	Ports                  []*model.ServicePort
	RateLimit              *traffic_manage.RateLimit
	SvcRateLimitRevision   string
	CircuitBreaker         *fault_tolerance.CircuitBreaker
	CircuitBreakerRevision string
	FaultDetect            *fault_tolerance.FaultDetector
	FaultDetectRevision    string
}

ServiceInfo 北极星服务结构体

func (*ServiceInfo) MatchService

func (s *ServiceInfo) MatchService(ns, name string) bool

type TLSMode

type TLSMode string
const (
	TLSModeTag                = "polarismesh.cn/tls-mode"
	TLSModeNone       TLSMode = "none"
	TLSModeStrict     TLSMode = "strict"
	TLSModePermissive TLSMode = "permissive"
)

type XDSBuilder

type XDSBuilder interface {
	// Init
	Init(*XDSClient, service.DiscoverServer)
	// Generate
	Generate(option *BuildOption) (interface{}, error)
}

XDSBuilder .

func GetBuilder

func GetBuilder(xdsType XDSType) XDSBuilder

GetBuilder .

type XDSClient

type XDSClient struct {
	RunType   RunType
	User      string
	Namespace string
	IPAddr    string
	PodIP     string
	Metadata  map[string]string
	Version   string
	Node      *core.Node
	TLSMode   TLSMode
}

XDSClient 客户端代码结构体

func (*XDSClient) GetSelfNamespace

func (n *XDSClient) GetSelfNamespace() string

GetSelfNamespace 获取 envoy 对应的 namespace 信息

func (*XDSClient) GetSelfService

func (n *XDSClient) GetSelfService() string

GetSelfService 获取 envoy 对应的 service 信息

func (*XDSClient) IsGateway

func (n *XDSClient) IsGateway() bool

func (*XDSClient) String

func (n *XDSClient) String() string

type XDSNodeManager

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

func NewXDSNodeManager

func NewXDSNodeManager() *XDSNodeManager

func (*XDSNodeManager) AddNodeIfAbsent

func (x *XDSNodeManager) AddNodeIfAbsent(streamId int64, node *core.Node)

func (*XDSNodeManager) DelNode

func (x *XDSNodeManager) DelNode(streamId int64)

func (*XDSNodeManager) GetNode

func (x *XDSNodeManager) GetNode(id string) *XDSClient

func (*XDSNodeManager) GetNodeByStreamID

func (x *XDSNodeManager) GetNodeByStreamID(streamId int64) *XDSClient

func (*XDSNodeManager) ListGatewayNodes

func (x *XDSNodeManager) ListGatewayNodes() []*XDSClient

func (*XDSNodeManager) ListSidecarNodes

func (x *XDSNodeManager) ListSidecarNodes() []*XDSClient

type XDSType

type XDSType int16
const (
	LDS XDSType
	RDS
	EDS
	CDS
	RLS
	SDS
)

Jump to

Keyboard shortcuts

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