-
Notifications
You must be signed in to change notification settings - Fork 8
/
types.go
75 lines (56 loc) · 2.59 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Package endpoint defines the interface for an endpoints provider. Endpoints providers communicate with the compute platforms
// and are primarily responsible for providing information regarding the endpoints for services, such as their IP
// addresses, port numbers and protocol information.
// Reference: https://github.com/flomesh-io/fsm/blob/main/DESIGN.md#3-endpoints-providers
package endpoint
import (
"fmt"
"net"
"github.com/flomesh-io/fsm/pkg/identity"
"github.com/flomesh-io/fsm/pkg/service"
)
// Provider is an interface to be implemented by components abstracting Kubernetes, and other compute/cluster providers
type Provider interface {
// ListEndpointsForService retrieves the IP addresses comprising the given service.
ListEndpointsForService(service.MeshService) []Endpoint
// ListEndpointsForIdentity retrieves the list of IP addresses for the given service account
ListEndpointsForIdentity(identity.ServiceIdentity) []Endpoint
// GetResolvableEndpointsForService returns the expected endpoints that are to be reached when the service FQDN is resolved under
// the scope of the provider
GetResolvableEndpointsForService(service.MeshService) []Endpoint
// GetID returns the unique identifier of the EndpointsProvider.
GetID() string
}
// Endpoint is a tuple of IP and Port representing an instance of a service
type Endpoint struct {
net.IP `json:"ip"`
Port `json:"port"`
Weight `json:"weight"`
Priority `json:"priority,omitempty"`
AppProtocol string `json:"appProtocol"`
// Zone is the zone the endpoint resides in.
Zone string `json:"name"`
// ClusterKey is a cluster key.
ClusterKey string `json:"cluster,omitempty"`
// LBType is a cluster load balancer type.
LBType string `json:"lbType,omitempty"`
// Path is a name with which a web service is accessed.
Path string `json:"path,omitempty"`
// ClusterID belongs to cluster.
ClusterID string `json:"clusterId,omitempty"`
// WithGateway with gateway.
WithGateway bool `json:"withGateway,omitempty"`
// WithMultiGateways with multi gateways.
WithMultiGateways bool `json:"withMultiGateways,omitempty"`
// ViaGateway via gateway.
ViaGateway string `json:"viaGateway,omitempty"`
}
func (ep Endpoint) String() string {
return fmt.Sprintf("(ip=%s, port=%d)", ep.IP, ep.Port)
}
// Port is a numerical type representing a port on which a service is exposed
type Port uint32
// Weight is the load assignment weight to the endpoint. The assignment works on the endpoints with the same priority.
type Weight uint32
// Priority is the priority of the remote cluster in locality based load balancing
type Priority uint32