This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 277
/
types.go
88 lines (72 loc) · 3.2 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
// Package smi implements the Service Mesh Interface (SMI) kubernetes client to observe and retrieve information
// regarding SMI traffic resources.
package smi
import (
"encoding/json"
"fmt"
"net/http"
smiAccess "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/access/v1alpha3"
smiSpecs "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs/v1alpha4"
smiSplit "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/split/v1alpha2"
"github.com/openservicemesh/osm/pkg/identity"
"github.com/openservicemesh/osm/pkg/logger"
"github.com/openservicemesh/osm/pkg/service"
)
var (
log = logger.New("smi-mesh-spec")
)
const (
// ServiceAccountKind is the kind specified for the destination and sources in an SMI TrafficTarget policy
ServiceAccountKind = "ServiceAccount"
// TCPRouteKind is the kind specified for the TCP route rules in an SMI Traffictarget policy
TCPRouteKind = "TCPRoute"
// HTTPRouteGroupKind is the kind specified for the HTTP route rules in an SMI Traffictarget policy
HTTPRouteGroupKind = "HTTPRouteGroup"
)
// 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
}
// 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
}
}
// GetSmiClientVersionHTTPHandler returns an http handler that returns supported smi version information
func GetSmiClientVersionHTTPHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
versionInfo := map[string]string{
"TrafficTarget": smiAccess.SchemeGroupVersion.String(),
"HTTPRouteGroup": smiSpecs.SchemeGroupVersion.String(),
"TCPRoute": smiSpecs.SchemeGroupVersion.String(),
"TrafficSplit": smiSplit.SchemeGroupVersion.String(),
}
if jsonVersionInfo, err := json.Marshal(versionInfo); err != nil {
log.Error().Err(err).Msgf("Error marshaling version info struct: %+v", versionInfo)
} else {
_, _ = fmt.Fprint(w, string(jsonVersionInfo))
}
})
}