spec

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package spec defines the spec for various objects in mesh.

Index

Constants

View Source
const (
	// RegistryTypeConsul is the consul registry type.
	RegistryTypeConsul = "consul"
	// RegistryTypeEureka is the eureka registry type.
	RegistryTypeEureka = "eureka"
	// RegistryTypeNacos is the eureka registry type.
	RegistryTypeNacos = "nacos"

	// GlobalTenant is the reserved name of the system scope tenant,
	// its services can be accessible in mesh wide.
	GlobalTenant = "global"

	// ServiceStatusUp indicates this service instance can accept ingress traffic
	ServiceStatusUp = "UP"

	// ServiceStatusOutOfService indicates this service instance can't accept ingress traffic
	ServiceStatusOutOfService = "OUT_OF_SERVICE"

	// WorkerAPIPort is the default port for worker's API server
	WorkerAPIPort = 13009

	// IngressPort is the default port for ingress controller
	IngressPort = 13010

	// HeartbeatInterval is the default heartbeat interval for checking service heartbeat
	HeartbeatInterval = "5s"

	// SecurityLevelPermissive is the level for not enabling mTLS.
	SecurityLevelPermissive = "permissive"

	// SecurityLevelStrict is the level for enabling mTLS.
	SecurityLevelStrict = "strict"

	// DefaultCommonName is the name of root ca cert.
	DefaultCommonName = "mesh-root-ca"

	// CertProviderSelfSign is the in-memory, self-sign cert provider.
	CertProviderSelfSign = "selfSign"

	// IngressControllerName is the name of easemesh ingress controller.
	IngressControllerName = "ingresscontroller"

	// PodEnvHostname is the name of the pod in environment variable.
	PodEnvHostname = "HOSTNAME"

	// PodEnvApplicationIP is the IP of the pod in environment variable.
	PodEnvApplicationIP = "APPLICATION_IP"

	// ServiceCanaryHeaderKey is the http header key of service canary.
	ServiceCanaryHeaderKey = "X-Mesh-Service-Canary"
)
View Source
const IngressControllerServerName = "ingresscontroller-server"

IngressControllerServerName returns the server name of ingress controller.

Variables

View Source
var (
	// ErrParamNotMatch means RESTful request URL's object name or other fields are not matched in this request's body
	ErrParamNotMatch = fmt.Errorf("param in url and body's spec not matched")
	// ErrAlreadyRegistered indicates this instance has already been registered
	ErrAlreadyRegistered = fmt.Errorf("service already registered")
	// ErrNoRegisteredYet indicates this instance haven't registered successfully yet
	ErrNoRegisteredYet = fmt.Errorf("service not registered yet")
	// ErrServiceNotFound indicates could find target service in its tenant or in global tenant
	ErrServiceNotFound = fmt.Errorf("can't find service in its tenant or in global tenant")
	// ErrServiceNotavailable indicates could find target service's available instances.
	ErrServiceNotavailable = fmt.Errorf("can't find service available instances")
)
View Source
var NoopServiceSelector = &ServiceSelector{}

NoopServiceSelector selects none of services or instances.

Functions

func IngressControllerHTTPServerSpec

func IngressControllerHTTPServerSpec(port int, rules []*IngressRule) (*supervisor.Spec, error)

IngressControllerHTTPServerSpec generates HTTP server spec for ingress. as ingress does not belong to a service, it is not a method of 'Service'

Types

type Admin

type Admin struct {
	// HeartbeatInterval is the interval for one service instance reporting its heartbeat.
	HeartbeatInterval string `json:"heartbeatInterval" jsonschema:"required,format=duration"`

	// RegistryTime indicates which protocol the registry center accepts.
	RegistryType string `json:"registryType" jsonschema:"required"`

	// APIPort is the port for worker's API server
	APIPort int `json:"apiPort" jsonschema:"required"`

	// IngressPort is the port for http server in mesh ingress
	IngressPort int `json:"ingressPort" jsonschema:"required"`

	ExternalServiceRegistry string `json:"externalServiceRegistry,omitempty"`

	CleanExternalRegistry bool `json:"cleanExternalRegistry,omitempty"`

	Security *Security `json:"security,omitempty"`

	// Sidecar injection relevant config.
	ImageRegistryURL          string `json:"imageRegistryURL,omitempty"`
	ImagePullPolicy           string `json:"imagePullPolicy,omitempty"`
	SidecarImageName          string `json:"sidecarImageName,omitempty"`
	AgentInitializerImageName string `json:"agentInitializerImageName,omitempty"`
	Log4jConfigName           string `json:"log4jConfigName,omitempty"`

	MonitorMTLS *MonitorMTLS `json:"monitorMTLS,omitempty"`
	WorkerSpec  WorkerSpec   `json:"workerSpec,omitempty"`
}

Admin is the spec of MeshController.

func (Admin) EnablemTLS

func (a Admin) EnablemTLS() bool

EnablemTLS indicates whether we should enable mTLS in mesh or not.

func (Admin) Validate

func (a Admin) Validate() error

Validate validates Spec.

type CanaryRule

type CanaryRule struct {
	ServiceInstanceLabels map[string]string                    `json:"serviceInstanceLabels" jsonschema:"required"`
	Headers               map[string]*stringtool.StringMatcher `json:"headers" jsonschema:"required"`
	URLs                  []*urlrule.URLRule                   `json:"urls" jsonschema:"required"`
}

CanaryRule is one matching rule for canary.

type Certificate

type Certificate struct {
	IP          string `json:"ip" jsonschema:"required"`
	ServiceName string `json:"servieName" jsonschema:"required"`
	CertBase64  string `json:"certBase64" jsonschema:"required"`
	KeyBase64   string `json:"keyBase64" jsonschema:"required"`
	TTL         string `json:"ttl" jsonschema:"required,format=duration"`
	SignTime    string `json:"signTime" jsonschema:"required,format=timerfc3339"`
	HOST        string `json:"host" jsonschema:"required"`
}

Certificate is one cert for mesh service instance or root CA.

type CustomResource

type CustomResource = customdata.Data

CustomResource defines the spec of a custom resource

type CustomResourceKind

type CustomResourceKind = customdata.Kind

CustomResourceKind defines the spec of a custom resource kind

type EgressServerSpec

type EgressServerSpec struct {
	KeepAlive        bool   `json:"keepAlive,omitempty"`
	KeepAliveTimeout string `json:"keepAliveTimeout,omitempty" jsonschema:"format=duration"`
}

EgressServerSpec is the spec of egress httpserver in worker

type HTTPMatch

type HTTPMatch struct {
	// Name is the name of the match for referencing in a TrafficTarget
	Name string `json:"name,omitempty"`

	// Methods for inbound traffic as defined in RFC 7231
	// https://tools.ietf.org/html/rfc7231#section-4
	Methods []string `json:"methods,omitempty"`

	// PathRegex is a regular expression defining the route
	PathRegex string `json:"pathRegex,omitempty"`
}

HTTPMatch defines an individual route for HTTP traffic

type HTTPRouteGroup

type HTTPRouteGroup struct {
	// Name is the name for referencing a HTTPRouteGroup
	Name string `json:"name" jsonschema:"required"`

	// Matches is a list of HTTPMatch to match traffic
	Matches []HTTPMatch `json:"matches,omitempty"`
}

HTTPRouteGroup defines the spec of a HTTP route group

type IdentityBindingSubject

type IdentityBindingSubject struct {
	// Kind is the type of Subject to allow ingress (Service)
	Kind string `json:"kind"`

	// Name of the Subject, i.e. ServiceName
	Name string `json:"name"`
}

IdentityBindingSubject is a service which should be allowed access to the TrafficTarget

type Ingress

type Ingress struct {
	Name  string         `json:"name" jsonschema:"required"`
	Rules []*IngressRule `json:"rules" jsonschema:"required"`
}

Ingress is the spec of mesh ingress

type IngressPath

type IngressPath struct {
	Path          string `json:"path" jsonschema:"required,pattern=^/"`
	RewriteTarget string `json:"rewriteTarget,omitempty"`
	Backend       string `json:"backend" jsonschema:"required"`
}

IngressPath is the path for a mesh ingress rule

type IngressRule

type IngressRule struct {
	Host  string         `json:"host,omitempty"`
	Paths []*IngressPath `json:"paths" jsonschema:"required"`
}

IngressRule is the rule for mesh ingress

type IngressServerSpec

type IngressServerSpec struct {
	KeepAlive        bool   `json:"keepAlive,omitempty"`
	KeepAliveTimeout string `json:"keepAliveTimeout,omitempty" jsonschema:"format=duration"`
}

IngressServerSpec is the spec of ingress httpserver in worker

type LoadBalance

type LoadBalance = proxy.LoadBalanceSpec

LoadBalance is the spec of service load balance.

type Mock

type Mock struct {
	// Enable is the mocking switch for this service.
	Enabled bool `json:"enabled" jsonschema:"required"`

	// Rules are the mocking matching and responding configurations.
	Rules []*mock.Rule `json:"rules,omitempty"`
}

Mock is the spec of configured and static API responses for this service.

type MonitorCert

type MonitorCert struct {
	CertBase64 string   `json:"certBase64" jsonschema:"required,format=base64"`
	KeyBase64  string   `json:"keyBase64" jsonschema:"required,format=base64"`
	Services   []string `json:"services" jsonschema:"required"`
}

MonitorCert is the spec for single pack of mTLS.

type MonitorMTLS

type MonitorMTLS struct {
	Enabled  bool   `json:"enabled" jsonschema:"required"`
	URL      string `json:"url" jsonschema:"required"`
	Username string `json:"username" jsonschema:"required"`
	Password string `json:"password" jsonschema:"required"`

	ReporterAppendType string         `json:"reporterAppendType,omitempty"`
	CaCertBase64       string         `json:"caCertBase64" jsonschema:"required,format=base64"`
	Certs              []*MonitorCert `json:"certs" jsonschema:"required"`
}

MonitorMTLS is the spec of mTLS specification of monitor.

type Observability

type Observability struct {
	OutputServer *ObservabilityOutputServer `json:"outputServer,omitempty"`
	Tracings     *ObservabilityTracings     `json:"tracings,omitempty"`
	Metrics      *ObservabilityMetrics      `json:"metrics,omitempty"`
}

Observability is the spec of service observability.

type ObservabilityMetrics

type ObservabilityMetrics struct {
	Enabled        bool                       `json:"enabled" jsonschema:"required"`
	Access         ObservabilityMetricsDetail `json:"access" jsonschema:"required"`
	Request        ObservabilityMetricsDetail `json:"request" jsonschema:"required"`
	JdbcStatement  ObservabilityMetricsDetail `json:"jdbcStatement" jsonschema:"required"`
	JdbcConnection ObservabilityMetricsDetail `json:"jdbcConnection" jsonschema:"required"`
	Rabbit         ObservabilityMetricsDetail `json:"rabbit" jsonschema:"required"`
	Kafka          ObservabilityMetricsDetail `json:"kafka" jsonschema:"required"`
	Redis          ObservabilityMetricsDetail `json:"redis" jsonschema:"required"`
	JvmGC          ObservabilityMetricsDetail `json:"jvmGc" jsonschema:"required"`
	JvmMemory      ObservabilityMetricsDetail `json:"jvmMemory" jsonschema:"required"`
	Md5Dictionary  ObservabilityMetricsDetail `json:"md5Dictionary" jsonschema:"required"`
}

ObservabilityMetrics is the metrics of observability.

type ObservabilityMetricsDetail

type ObservabilityMetricsDetail struct {
	Enabled  bool   `json:"enabled" jsonschema:"required"`
	Interval int    `json:"interval" jsonschema:"required"`
	Topic    string `json:"topic" jsonschema:"required"`
}

ObservabilityMetricsDetail is the metrics detail of observability.

type ObservabilityOutputServer

type ObservabilityOutputServer struct {
	Enabled         bool   `json:"enabled" jsonschema:"required"`
	BootstrapServer string `json:"bootstrapServer" jsonschema:"required"`
	Timeout         int    `json:"timeout" jsonschema:"required"`
}

ObservabilityOutputServer is the output server of observability.

type ObservabilityTracings

type ObservabilityTracings struct {
	Enabled     bool                              `json:"enabled" jsonschema:"required"`
	SampleByQPS int                               `json:"sampleByQPS" jsonschema:"required"`
	Output      ObservabilityTracingsOutputConfig `json:"output" jsonschema:"required"`

	Request      ObservabilityTracingsDetail `json:"request" jsonschema:"required"`
	RemoteInvoke ObservabilityTracingsDetail `json:"remoteInvoke" jsonschema:"required"`
	Kafka        ObservabilityTracingsDetail `json:"kafka" jsonschema:"required"`
	Jdbc         ObservabilityTracingsDetail `json:"jdbc" jsonschema:"required"`
	Redis        ObservabilityTracingsDetail `json:"redis" jsonschema:"required"`
	Rabbit       ObservabilityTracingsDetail `json:"rabbit" jsonschema:"required"`
}

ObservabilityTracings is the tracings of observability.

type ObservabilityTracingsDetail

type ObservabilityTracingsDetail struct {
	Enabled       bool   `json:"enabled" jsonschema:"required"`
	ServicePrefix string `json:"servicePrefix" jsonschema:"required"`
}

ObservabilityTracingsDetail is the tracing detail of observability.

type ObservabilityTracingsOutputConfig

type ObservabilityTracingsOutputConfig struct {
	Enabled         bool   `json:"enabled" jsonschema:"required"`
	ReportThread    int    `json:"reportThread" jsonschema:"required"`
	Topic           string `json:"topic" jsonschema:"required"`
	MessageMaxBytes int    `json:"messageMaxBytes" jsonschema:"required"`
	QueuedMaxSpans  int    `json:"queuedMaxSpans" jsonschema:"required"`
	QueuedMaxSize   int    `json:"queuedMaxSize" jsonschema:"required"`
	MessageTimeout  int    `json:"messageTimeout" jsonschema:"required"`
}

ObservabilityTracingsOutputConfig is the tracing output configuration

type Resilience

type Resilience struct {
	RateLimiter    *ratelimiter.Rule              `json:"rateLimiter,omitempty"`
	CircuitBreaker *resilience.CircuitBreakerRule `json:"circuitBreaker,omitempty"`
	Retry          *resilience.RetryRule          `json:"retry,omitempty"`
	TimeLimiter    *TimeLimiterRule               `json:"timeLimiter,omitempty"`
	FailureCodes   []int                          `json:"failureCodes,omitempty" jsonschema:"uniqueItems=true"`
}

Resilience is the spec of service resilience.

type Security

type Security struct {
	MTLSMode     string `json:"mtlsMode" jsonschema:"required"`
	CertProvider string `json:"certProvider" jsonschema:"required"`

	RootCertTTL string `json:"rootCertTTL" jsonschema:"required,format=duration"`
	AppCertTTL  string `json:"appCertTTL" jsonschema:"required,format=duration"`
}

Security is the spec for mesh-wide security.

type Service

type Service struct {
	// Empty means mesh registry itself.
	RegistryName   string `json:"registryName,omitempty"`
	Name           string `json:"name" jsonschema:"required"`
	RegisterTenant string `json:"registerTenant" jsonschema:"required"`

	Sidecar       *Sidecar       `json:"sidecar" jsonschema:"required"`
	Mock          *Mock          `json:"mock,omitempty"`
	Resilience    *Resilience    `json:"resilience,omitempty"`
	LoadBalance   *LoadBalance   `json:"loadBalance,omitempty"`
	Observability *Observability `json:"observability,omitempty"`
}

Service contains the information of service.

func (*Service) ApplicationInstanceSpec

func (s *Service) ApplicationInstanceSpec(port uint32) *ServiceInstanceSpec

ApplicationInstanceSpec returns instance spec of application.

func (*Service) BackendName

func (s *Service) BackendName() string

BackendName returns backend service name

func (*Service) IngressControllerPipelineName

func (s *Service) IngressControllerPipelineName() string

IngressControllerPipelineName returns the pipeline name of ingress controller.

func (*Service) IngressControllerPipelineSpec

func (s *Service) IngressControllerPipelineSpec(instanceSpecs []*ServiceInstanceSpec,
	canaries []*ServiceCanary, cert, rootCert *Certificate,
) (*supervisor.Spec, error)

IngressControllerPipelineSpec generates a spec for ingress controller pipeline spec.

func (*Service) SidecarEgressHTTPServerSpec

func (s *Service) SidecarEgressHTTPServerSpec(keepalive bool, timeout string) (*supervisor.Spec, error)

SidecarEgressHTTPServerSpec returns a spec for egress HTTP server

func (*Service) SidecarEgressPipelineName

func (s *Service) SidecarEgressPipelineName() string

SidecarEgressPipelineName returns egress pipeline name

func (*Service) SidecarEgressPipelineSpec

func (s *Service) SidecarEgressPipelineSpec(instanceSpecs []*ServiceInstanceSpec,
	canaries []*ServiceCanary, appCert, rootCert *Certificate,
) (*supervisor.Spec, error)

SidecarEgressPipelineSpec returns a spec for sidecar egress pipeline

func (*Service) SidecarEgressServerName

func (s *Service) SidecarEgressServerName() string

SidecarEgressServerName returns egress HTTP server name

func (*Service) SidecarIngressHTTPServerName

func (s *Service) SidecarIngressHTTPServerName() string

SidecarIngressHTTPServerName returns the ingress server name

func (*Service) SidecarIngressHTTPServerSpec

func (s *Service) SidecarIngressHTTPServerSpec(keepalive bool, timeout string,
	cert, rootCert *Certificate,
) (*supervisor.Spec, error)

SidecarIngressHTTPServerSpec generates a spec for sidecar ingress HTTP server

func (*Service) SidecarIngressPipelineName

func (s *Service) SidecarIngressPipelineName() string

SidecarIngressPipelineName returns the ingress pipeline name

func (*Service) SidecarIngressPipelineSpec

func (s *Service) SidecarIngressPipelineSpec(applicationPort uint32) (*supervisor.Spec, error)

SidecarIngressPipelineSpec returns a spec for sidecar ingress pipeline

type ServiceCanary

type ServiceCanary struct {
	Name string `json:"name" jsonschema:"required"`
	// Priority must be [1, 9], the default is 5 if user does not set it.
	// The smaller number get higher priority.
	// The order is sorted by name alphabetically in the same priority.
	Priority     int              `json:"priority"`
	Selector     *ServiceSelector `json:"selector" jsonschema:"required"`
	TrafficRules *TrafficRules    `json:"trafficRules" jsonschema:"required"`
}

ServiceCanary is the service canary entry.

func (ServiceCanary) Validate

func (sc ServiceCanary) Validate() error

Validate validates ServiceCanary.

type ServiceDeployment

type ServiceDeployment struct {
	// The spec of Deployment or StatefulSet of Kubernetes.
	App interface{} `json:"app" jsonschema:"required"`

	// All specs of ConfigMaps in volumes of the spec.
	ConfigMaps []*v1.ConfigMap `json:"configMaps,omitempty"`

	// All specs of Secrets in volumes of the spec.
	Secrets []*v1.Secret `json:"secrets,omitempty"`
}

ServiceDeployment contains the information of service deployment.

type ServiceInstanceSpec

type ServiceInstanceSpec struct {
	// AgentType supports EaseAgent, GoSDK, None(same as empty value).
	AgentType    string `json:"agentType" jsonschema:"required"`
	RegistryName string `json:"registryName" jsonschema:"required"`
	// Provide by registry client
	ServiceName  string            `json:"serviceName" jsonschema:"required"`
	InstanceID   string            `json:"instanceID" jsonschema:"required"`
	IP           string            `json:"ip" jsonschema:"required"`
	Port         uint32            `json:"port" jsonschema:"required"`
	RegistryTime string            `json:"registryTime,omitempty"`
	Labels       map[string]string `json:"labels,omitempty"`

	// Set by heartbeat timer event or API
	Status string `json:"status"`
}

ServiceInstanceSpec is the spec of service instance. FIXME: Use the unified struct: serviceregistry.ServiceInstanceSpec.

func (*ServiceInstanceSpec) Key

func (s *ServiceInstanceSpec) Key() string

Key returns the key of ServiceInstanceSpec.

type ServiceInstanceStatus

type ServiceInstanceStatus struct {
	ServiceName string `json:"serviceName" jsonschema:"required"`
	InstanceID  string `json:"instanceID" jsonschema:"required"`
	// RFC3339 format
	LastHeartbeatTime string `json:"lastHeartbeatTime" jsonschema:"required,format=timerfc3339"`
}

ServiceInstanceStatus is the status of service instance.

type ServiceSelector

type ServiceSelector struct {
	MatchServices       []string          `json:"matchServices" jsonschema:"required,uniqueItems=true"`
	MatchInstanceLabels map[string]string `json:"matchInstanceLabels" jsonschema:"required"`
}

ServiceSelector is to select service instances according to service names and labels.

func (*ServiceSelector) MatchInstance

func (s *ServiceSelector) MatchInstance(serviceName string, instancelabels map[string]string) bool

MatchInstance returns whether selecting the service instance by service name and instance labels.

func (*ServiceSelector) MatchService

func (s *ServiceSelector) MatchService(serviceName string) bool

MatchService returns whether selecting the given service.

type Sidecar

type Sidecar struct {
	DiscoveryType   string `json:"discoveryType" jsonschema:"required"`
	Address         string `json:"address" jsonschema:"required"`
	IngressPort     int    `json:"ingressPort" jsonschema:"required"`
	IngressProtocol string `json:"ingressProtocol" jsonschema:"required"`
	EgressPort      int    `json:"egressPort" jsonschema:"required"`
	EgressProtocol  string `json:"egressProtocol" jsonschema:"required"`
}

Sidecar is the spec of service sidecar.

type Tenant

type Tenant struct {
	Name string `json:"name"`

	Services []string `json:"services,omitempty"`
	// Format: RFC3339
	CreatedAt   string `json:"createdAt"`
	Description string `json:"description,omitempty"`
}

Tenant contains the information of tenant.

type TimeLimiterRule

type TimeLimiterRule struct {
	Timeout string `json:"timeout" jsonschema:"required,format=duration"`
}

TimeLimiterRule is the spec of TimeLimiter.

type TrafficRules

type TrafficRules struct {
	Headers map[string]*stringtool.StringMatcher `json:"headers" jsonschema:"required"`
}

TrafficRules is the rules of traffic.

func (*TrafficRules) Clone

func (tr *TrafficRules) Clone() *TrafficRules

Clone clones TrafficRules.

type TrafficTarget

type TrafficTarget struct {
	// Name is the name for referencing a TrafficTarget
	Name string `json:"name" jsonschema:"required"`

	// Destination is the service to allow ingress traffic
	Destination IdentityBindingSubject `json:"destination"`

	// Sources are the services to allow egress traffic
	Sources []IdentityBindingSubject `json:"sources,omitempty"`

	// Rules are the traffic rules to allow (HTTPRoutes)
	Rules []TrafficTargetRule `json:"rules,omitempty"`
}

TrafficTarget is the specification of a TrafficTarget

type TrafficTargetRule

type TrafficTargetRule struct {
	// Kind is the kind of TrafficSpec to allow
	Kind string `json:"kind"`

	// Name of the TrafficSpec to use
	Name string `json:"name"`

	// Matches is a list of TrafficSpec routes to allow traffic for
	// +optional
	Matches []string `json:"matches,omitempty"`
}

TrafficTargetRule is the TrafficSpec to allow for a TrafficTarget

type WorkerSpec

type WorkerSpec struct {
	Ingress IngressServerSpec `json:"ingress,omitempty"`
	Egress  EgressServerSpec  `json:"egress,omitempty"`
}

WorkerSpec is the spec of worker

Jump to

Keyboard shortcuts

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