Skip to content

Commit 2664362

Browse files
authored
OSPP2023-23aaf0425 (#66)
* feat: Init PluginServer * feat: add ratelimit plugin * chore: delete some comments
1 parent ac5cff2 commit 2664362

38 files changed

+2611
-48
lines changed

control_plane.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
package opensergo
1616

1717
import (
18+
"github.com/opensergo/opensergo-control-plane/pkg/api/v1alpha1"
19+
"github.com/opensergo/opensergo-control-plane/pkg/plugin/pl/builtin"
20+
ratelimit_plugin "github.com/opensergo/opensergo-control-plane/pkg/plugin/pl/builtin/ratelimit"
1821
"log"
1922
"os"
2023
"sync"
@@ -38,7 +41,7 @@ type ControlPlane struct {
3841
func NewControlPlane() (*ControlPlane, error) {
3942
cp := &ControlPlane{}
4043

41-
operator, err := controller.NewKubernetesOperator(cp.sendMessage)
44+
operator, err := controller.NewKubernetesOperator(cp.sendMessage, cp.NotifyPluginHandler)
4245
if err != nil {
4346
return nil, err
4447
}
@@ -71,6 +74,32 @@ func (c *ControlPlane) Start() error {
7174
return nil
7275
}
7376

77+
func (c *ControlPlane) NotifyPluginHandler(pluginName string, e any) error {
78+
client, err := c.server.PluginServer.GetPluginClient(pluginName)
79+
if err != nil {
80+
log.Printf("Error:%s\n", err.Error())
81+
}
82+
switch pluginName {
83+
case builtin.RateLimitServicePluginName:
84+
raw, ok := client.(ratelimit_plugin.RateLimit)
85+
if !ok {
86+
return errors.New("can't convert ratelimit plugin to normal wrapper")
87+
}
88+
l, ok := e.(*v1alpha1.RateLimitStrategy)
89+
if !ok {
90+
log.Printf("Error: %s\n", "can't convert event to ratelimit strategy")
91+
}
92+
err = builtin.NotifyPluginRateLimit(raw, l)
93+
if err != nil {
94+
return err
95+
}
96+
default:
97+
log.Printf("unknown plugin name: %s\n", pluginName)
98+
}
99+
return nil
100+
101+
}
102+
74103
func (c *ControlPlane) sendMessage(namespace, app, kind string, dataWithVersion *trpb.DataWithVersion, status *trpb.Status, respId string) error {
75104
connections, exists := c.server.ConnectionManager().Get(namespace, app, kind)
76105
if !exists || connections == nil {
@@ -94,6 +123,7 @@ func (c *ControlPlane) sendMessageToStream(stream model.OpenSergoTransportStream
94123
if stream == nil {
95124
return nil
96125
}
126+
97127
return stream.SendMsg(&trpb.SubscribeResponse{
98128
Status: status,
99129
Ack: "",

go.mod

+62-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,80 @@
11
module github.com/opensergo/opensergo-control-plane
22

3-
go 1.14
3+
go 1.18
44

55
require (
66
github.com/alibaba/sentinel-golang v1.0.3
7-
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc
87
github.com/envoyproxy/go-control-plane v0.10.3-0.20221109183938-2935a23e638f
98
github.com/envoyproxy/protoc-gen-validate v0.6.7
109
github.com/go-logr/logr v0.4.0
1110
github.com/golang/protobuf v1.5.2
12-
github.com/json-iterator/go v1.1.12 // indirect
13-
github.com/kr/pretty v0.3.0 // indirect
11+
github.com/hashicorp/go-hclog v1.1.0
12+
github.com/hashicorp/go-plugin v1.4.10
13+
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2
14+
github.com/hashicorp/go-secure-stdlib/pluginutil/v2 v2.0.4
1415
github.com/pkg/errors v0.9.1
15-
github.com/rogpeppe/go-internal v1.8.0 // indirect
1616
go.uber.org/atomic v1.7.0
1717
google.golang.org/genproto v0.0.0-20220329172620-7be39ac1afc7
1818
google.golang.org/grpc v1.51.0
1919
google.golang.org/protobuf v1.28.1
20-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
20+
gopkg.in/yaml.v3 v3.0.1
2121
k8s.io/apimachinery v0.21.4
2222
k8s.io/client-go v0.21.4
2323
sigs.k8s.io/controller-runtime v0.9.7
2424
)
25+
26+
require (
27+
cloud.google.com/go v0.65.0 // indirect
28+
github.com/beorn7/perks v1.0.1 // indirect
29+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
30+
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc // indirect
31+
github.com/davecgh/go-spew v1.1.1 // indirect
32+
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
33+
github.com/fatih/color v1.7.0 // indirect
34+
github.com/fsnotify/fsnotify v1.4.9 // indirect
35+
github.com/gogo/protobuf v1.3.2 // indirect
36+
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
37+
github.com/google/go-cmp v0.5.7 // indirect
38+
github.com/google/gofuzz v1.1.0 // indirect
39+
github.com/google/uuid v1.1.2 // indirect
40+
github.com/googleapis/gnostic v0.5.5 // indirect
41+
github.com/hashicorp/go-uuid v1.0.2 // indirect
42+
github.com/hashicorp/golang-lru v0.5.4 // indirect
43+
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
44+
github.com/imdario/mergo v0.3.12 // indirect
45+
github.com/json-iterator/go v1.1.12 // indirect
46+
github.com/kr/pretty v0.3.0 // indirect
47+
github.com/mattn/go-colorable v0.1.6 // indirect
48+
github.com/mattn/go-isatty v0.0.12 // indirect
49+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
50+
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
51+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
52+
github.com/modern-go/reflect2 v1.0.2 // indirect
53+
github.com/oklog/run v1.0.0 // indirect
54+
github.com/prometheus/client_golang v1.11.0 // indirect
55+
github.com/prometheus/client_model v0.3.0 // indirect
56+
github.com/prometheus/common v0.26.0 // indirect
57+
github.com/prometheus/procfs v0.6.0 // indirect
58+
github.com/rogpeppe/go-internal v1.8.0 // indirect
59+
github.com/spf13/pflag v1.0.5 // indirect
60+
golang.org/x/crypto v0.8.0 // indirect
61+
golang.org/x/net v0.9.0 // indirect
62+
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
63+
golang.org/x/sys v0.7.0 // indirect
64+
golang.org/x/term v0.7.0 // indirect
65+
golang.org/x/text v0.9.0 // indirect
66+
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
67+
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
68+
google.golang.org/appengine v1.6.7 // indirect
69+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
70+
gopkg.in/inf.v0 v0.9.1 // indirect
71+
gopkg.in/yaml.v2 v2.4.0 // indirect
72+
k8s.io/api v0.21.4 // indirect
73+
k8s.io/apiextensions-apiserver v0.21.4 // indirect
74+
k8s.io/component-base v0.21.4 // indirect
75+
k8s.io/klog/v2 v2.8.0 // indirect
76+
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
77+
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 // indirect
78+
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
79+
sigs.k8s.io/yaml v1.2.0 // indirect
80+
)

0 commit comments

Comments
 (0)