-
Notifications
You must be signed in to change notification settings - Fork 7
/
types.go
98 lines (79 loc) · 3.64 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Package smi implements the Service Mesh Interface (SMI) kubernetes client to observe and retrieve information
// regarding SMI traffic resources.
package smi
import (
access "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/access/v1alpha3"
spec "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs/v1alpha4"
split "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/split/v1alpha4"
"github.com/flomesh-io/fsm/pkg/identity"
"github.com/flomesh-io/fsm/pkg/k8s"
"github.com/flomesh-io/fsm/pkg/k8s/informers"
"github.com/flomesh-io/fsm/pkg/logger"
"github.com/flomesh-io/fsm/pkg/service"
)
var (
log = logger.New("smi-mesh-spec")
)
// Client is a type that implements the smi.MeshSpec interface related to Kubernetes SMI resources
type Client struct {
providerIdent string
informers *informers.InformerCollection
fsmNamespace string
kubeController k8s.Controller
}
// MeshSpec is an interface declaring functions, which provide the specs for a service mesh declared with SMI.
type MeshSpec interface {
// ListTrafficSplits lists SMI TrafficSplit resources
ListTrafficSplits(...TrafficSplitListOption) []*split.TrafficSplit
// ListServiceAccounts lists ServiceAccount resources specified in SMI TrafficTarget resources
ListServiceAccounts() []identity.K8sServiceAccount
// ListHTTPTrafficSpecs lists SMI HTTPRouteGroup resources
ListHTTPTrafficSpecs() []*spec.HTTPRouteGroup
// GetHTTPRouteGroup returns an SMI HTTPRouteGroup resource given its name of the form <namespace>/<name>
GetHTTPRouteGroup(string) *spec.HTTPRouteGroup
// ListTCPTrafficSpecs lists SMI TCPRoute resources
ListTCPTrafficSpecs() []*spec.TCPRoute
// GetTCPRoute returns an SMI TCPRoute resource given its name of the form <namespace>/<name>
GetTCPRoute(string) *spec.TCPRoute
// ListTrafficTargets lists SMI TrafficTarget resources. An optional filter can be applied to filter the
// returned list
ListTrafficTargets(...TrafficTargetListOption) []*access.TrafficTarget
}
// TrafficTargetListOpt specifies the options used to filter TrafficTarget objects as a part of its lister
type TrafficTargetListOpt struct {
Destination identity.K8sServiceAccount
}
// TrafficTargetListOption is a function type that implements filters on TrafficTarget lister
type TrafficTargetListOption func(o *TrafficTargetListOpt)
// WithTrafficTargetDestination applies a filter based on the destination service account to the TrafficTarget lister
func WithTrafficTargetDestination(d identity.K8sServiceAccount) TrafficTargetListOption {
return func(o *TrafficTargetListOpt) {
o.Destination = d
}
}
// TrafficSplitListOpt specifies the options used to filter TrafficSplit objects as a part of its lister
type TrafficSplitListOpt struct {
ApexService service.MeshService
BackendService service.MeshService
KubeController k8s.Controller
}
// TrafficSplitListOption is a function type that implements filters on the TrafficSplit lister
type TrafficSplitListOption func(o *TrafficSplitListOpt)
// WithTrafficSplitApexService applies a filter based on the apex service to the TrafficSplit lister
func WithTrafficSplitApexService(s service.MeshService) TrafficSplitListOption {
return func(o *TrafficSplitListOpt) {
o.ApexService = s
}
}
// WithTrafficSplitBackendService applies a filter based on the backend service to the TrafficSplit lister
func WithTrafficSplitBackendService(s service.MeshService) TrafficSplitListOption {
return func(o *TrafficSplitListOpt) {
o.BackendService = s
}
}
// WithKubeController adds a KubeController to the TrafficSplit lister
func WithKubeController(c k8s.Controller) TrafficSplitListOption {
return func(o *TrafficSplitListOpt) {
o.KubeController = c
}
}