Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSPP2023-23aaf0425 #66

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package opensergo

import (
"github.com/opensergo/opensergo-control-plane/pkg/api/v1alpha1"
"github.com/opensergo/opensergo-control-plane/pkg/plugin/pl/builtin"
ratelimit_plugin "github.com/opensergo/opensergo-control-plane/pkg/plugin/pl/builtin/ratelimit"
"log"
"os"
"sync"
Expand All @@ -38,7 +41,7 @@ type ControlPlane struct {
func NewControlPlane() (*ControlPlane, error) {
cp := &ControlPlane{}

operator, err := controller.NewKubernetesOperator(cp.sendMessage)
operator, err := controller.NewKubernetesOperator(cp.sendMessage, cp.NotifyPluginHandler)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,6 +74,32 @@ func (c *ControlPlane) Start() error {
return nil
}

func (c *ControlPlane) NotifyPluginHandler(pluginName string, e any) error {
client, err := c.server.PluginServer.GetPluginClient(pluginName)
if err != nil {
log.Printf("Error:%s\n", err.Error())
}
switch pluginName {
case builtin.RateLimitServicePluginName:
raw, ok := client.(ratelimit_plugin.RateLimit)
if !ok {
return errors.New("can't convert ratelimit plugin to normal wrapper")
}
l, ok := e.(*v1alpha1.RateLimitStrategy)
if !ok {
log.Printf("Error: %s\n", "can't convert event to ratelimit strategy")
}
err = builtin.NotifyPluginRateLimit(raw, l)
if err != nil {
return err
}
default:
log.Printf("unknown plugin name: %s\n", pluginName)
}
return nil

}

func (c *ControlPlane) sendMessage(namespace, app, kind string, dataWithVersion *trpb.DataWithVersion, status *trpb.Status, respId string) error {
connections, exists := c.server.ConnectionManager().Get(namespace, app, kind)
if !exists || connections == nil {
Expand All @@ -94,6 +123,7 @@ func (c *ControlPlane) sendMessageToStream(stream model.OpenSergoTransportStream
if stream == nil {
return nil
}

return stream.SendMsg(&trpb.SubscribeResponse{
Status: status,
Ack: "",
Expand Down
68 changes: 62 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,80 @@
module github.com/opensergo/opensergo-control-plane

go 1.14
go 1.18

require (
github.com/alibaba/sentinel-golang v1.0.3
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc
github.com/envoyproxy/go-control-plane v0.10.3-0.20221109183938-2935a23e638f
github.com/envoyproxy/protoc-gen-validate v0.6.7
github.com/go-logr/logr v0.4.0
github.com/golang/protobuf v1.5.2
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/hashicorp/go-hclog v1.1.0
github.com/hashicorp/go-plugin v1.4.10
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2
github.com/hashicorp/go-secure-stdlib/pluginutil/v2 v2.0.4
github.com/pkg/errors v0.9.1
github.com/rogpeppe/go-internal v1.8.0 // indirect
go.uber.org/atomic v1.7.0
google.golang.org/genproto v0.0.0-20220329172620-7be39ac1afc7
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.21.4
k8s.io/client-go v0.21.4
sigs.k8s.io/controller-runtime v0.9.7
)

require (
cloud.google.com/go v0.65.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.11.0+incompatible // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.21.4 // indirect
k8s.io/apiextensions-apiserver v0.21.4 // indirect
k8s.io/component-base v0.21.4 // indirect
k8s.io/klog/v2 v2.8.0 // indirect
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 // indirect
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading