resource

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 53 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PassthroughClusterName  = "PassthroughCluster"
	RouteConfigName         = "polaris-router"
	OutBoundRouteConfigName = "polaris-outbound-router"
	InBoundRouteConfigName  = "polaris-inbound-cluster"
	OdcdsRouteConfigName    = "polaris-odcds-router"
	InternalOdcdsHeader     = "internal-service-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"
	// SidecarRegisterService xds metadata key when node what register service from envoy healthcheck
	// value example: [{"name":"","ports":{"TCP":[8080],"DUBBO":[28080]},"health_check_path":"","health_check_port":8080,"health_check_ttl":5}]
	SidecarRegisterService = "sidecar.polarismesh.cn/registerServices"
	// SidecarTLSModeTag .
	SidecarTLSModeTag = "sidecar.polarismesh.cn/tlsMode"
	// SidecarOpenOnDemandFeature .
	SidecarOpenOnDemandFeature = "sidecar.polarismesh.cn/openOnDemand"
	// SidecarOpenOnDemandServer .
	SidecarOpenOnDemandServer = "sidecar.polarismesh.cn/demandServer"
)
View Source
const (
	EnvoyHttpFilter_OnDemand = "envoy.filters.http.on_demand"
)
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{},
}
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 BuildOnDemandRouteTypedPerFilterConfig added in v1.18.0

func BuildOnDemandRouteTypedPerFilterConfig() *anypb.Any

func BuildRateLimitActionHeaderValueMatch

func BuildRateLimitActionHeaderValueMatch(key, value string,
	arguments ...*apitraffic.MatchArgument) *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, opt *BuildOption) *route.WeightedCluster

func DumpSnapShotJSON

func DumpSnapShotJSON(snapshot cache.ResourceSnapshot) []byte

func EnableTLS added in v1.18.0

func EnableTLS(t TLSMode) bool

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 GetEnvoyMetaField added in v1.18.0

func GetEnvoyMetaField[T any](meta *_struct.Struct, fileName string, fType T) (T, bool)

func Init added in v1.18.0

func Init()

func IsNormalEndpoint

func IsNormalEndpoint(ins *apiservice.Instance) bool

func MakeDefaultFilterChain

func MakeDefaultFilterChain() *listenerv3.FilterChain

func MakeDefaultRoute

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

默认路由

func MakeGatewayBoundHCM

func MakeGatewayBoundHCM(svcKey model.ServiceKey, opt *BuildOption) *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, opt *BuildOption) *route.Route

func MakeHealthCheck

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

Translate the FaultDetector configuration of Polaris into HealthCheck

func MakeInBoundRouteConfigName added in v1.18.0

func MakeInBoundRouteConfigName(svcKey model.ServiceKey, demand bool) string

MakeInBoundRouteConfigName .

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,
	opt *BuildOption) string

MakeServiceName .

func MakeSidecarBoundHCM

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

func MakeSidecarLocalRateLimit

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

func MakeSidecarOnDemandOutBoundHCM added in v1.18.0

func MakeSidecarOnDemandOutBoundHCM(svcKey model.ServiceKey, option *BuildOption) *hcm.HttpConnectionManager

func MakeSidecarRoute

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

func MakeTLSTransportSocket

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

func MakeVHDSServiceName added in v1.18.0

func MakeVHDSServiceName(prefix string, svcKey model.ServiceKey) string

MakeVHDSServiceName .

func MustNewAny

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

func ParseNodeID

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

func SupportTLS added in v1.18.0

func SupportTLS(x XDSType) bool

func ToJSONArray

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

func ToYamlArray added in v1.18.0

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

func YamlEncode

func YamlEncode(any interface{}) []byte

Types

type BuildOption

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

	// SelfService 当前服务信息,只有处理 INBOUND 级别的信息才能设置
	SelfService model.ServiceKey
	// 不是必须,只有在 EDS 生成,并且是处理 INBOUND 的时候才会设置
	Client *XDSClient
	// TrafficDirection 设置流量的出入方向,INBOUND|OUTBOUND
	TrafficDirection corev3.TrafficDirection
	// ForceDelete 如果设置了该字段值为 true, 则不会真正执行 XDS 的构建工作, 仅仅生成对应资源的 Name 名称用于清理
	ForceDelete bool
	// contains filtered or unexported fields
}

func (*BuildOption) Clone

func (opt *BuildOption) Clone() *BuildOption

func (*BuildOption) CloseEnvoyDemand added in v1.18.0

func (opt *BuildOption) CloseEnvoyDemand()

func (*BuildOption) HasTls added in v1.18.0

func (opt *BuildOption) HasTls() bool

func (*BuildOption) IsDemand added in v1.18.0

func (opt *BuildOption) IsDemand() bool

func (*BuildOption) OpenEnvoyDemand added in v1.18.0

func (opt *BuildOption) OpenEnvoyDemand()

type EnvoyNodeView added in v1.18.0

type EnvoyNodeView struct {
	ID           string
	RunType      RunType
	User         string
	Namespace    string
	IPAddr       string
	PodIP        string
	Metadata     map[string]string
	Version      string
	TLSMode      TLSMode
	OpenOnDemand bool
}

type PolarisNodeHash

type PolarisNodeHash struct {
	NodeMgr *XDSNodeManager
}

PolarisNodeHash 存放 hash 方法

type RegisterService added in v1.18.0

type RegisterService struct {
	Name            string           `json:"name"`
	Ports           map[string][]int `json:"ports"`
	HealthCheckPath string           `json:"health_check_path"`
	HealthCheckPort int              `json:"health_check_port"`
	HealthCheckTtl  int              `json:"health_check_ttl"`
	TracingSampling float64          `json:"tracing_sampling"`
}

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) Equal added in v1.18.0

func (s *ServiceInfo) Equal(o *ServiceInfo) bool

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(service.DiscoverServer)
	// Generate
	Generate(option *BuildOption) (interface{}, error)
}

XDSBuilder .

type XDSClient

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

XDSClient 客户端代码结构体

func ParseXDSClient added in v1.18.0

func ParseXDSClient(node *core.Node) *XDSClient

ParseXDSClient .

func (*XDSClient) GetNodeID added in v1.18.0

func (n *XDSClient) GetNodeID() string

func (*XDSClient) GetRegisterServices added in v1.18.0

func (n *XDSClient) GetRegisterServices() []*RegisterService

func (*XDSClient) GetSelfNamespace

func (n *XDSClient) GetSelfNamespace() string

GetSelfNamespace 获取 envoy 对应的 namespace 信息

func (*XDSClient) GetSelfService

func (n *XDSClient) GetSelfService() string

GetSelfService 获取 envoy 对应的 service 信息

func (*XDSClient) GetSelfServiceKey added in v1.18.0

func (n *XDSClient) GetSelfServiceKey() model.ServiceKey

GetSelfServiceKey 获取 envoy 对应的 service 信息

func (*XDSClient) IsGateway

func (n *XDSClient) IsGateway() bool

func (*XDSClient) ResourceKey added in v1.18.0

func (n *XDSClient) ResourceKey() string

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) HasEnvoyNodes added in v1.18.0

func (x *XDSNodeManager) HasEnvoyNodes() bool

func (*XDSNodeManager) ListEnvoyNodes added in v1.18.0

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

func (*XDSNodeManager) ListEnvoyNodesView added in v1.18.0

func (x *XDSNodeManager) ListEnvoyNodesView(run RunType) []*EnvoyNodeView

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
	VHDS
	UnknownXDS
)

func FormatTypeUrl added in v1.18.0

func FormatTypeUrl(typeUrl string) XDSType

func FromSimpleXDS added in v1.18.0

func FromSimpleXDS(s string) XDSType

func (XDSType) ResourceType added in v1.18.0

func (x XDSType) ResourceType() resourcev3.Type

func (XDSType) String added in v1.18.0

func (x XDSType) String() string

Jump to

Keyboard shortcuts

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