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

Clean up gRPC API for plugins #1197

Merged
merged 5 commits into from
Aug 21, 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
2 changes: 1 addition & 1 deletion cmd/executor/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (*EchoExecutor) Execute(_ context.Context, in executor.ExecuteInput) (execu
}

return executor.ExecuteOutput{
Data: data,
Message: api.NewCodeBlockMessage(data, true),
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/executor/gh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (e *GHExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (exe

if cmd.Create == nil || cmd.Create.Issue == nil {
return executor.ExecuteOutput{
Data: fmt.Sprintf("Usage: %s create issue KIND/NAME", pluginName),
Message: api.NewCodeBlockMessage(fmt.Sprintf("Usage: %s create issue KIND/NAME", pluginName), false),
}, nil
}

Expand Down Expand Up @@ -114,7 +114,7 @@ func (e *GHExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (exe
}

return executor.ExecuteOutput{
Data: fmt.Sprintf("New issue created successfully! 🎉\n\nIssue URL: %s", issueURL),
Message: api.NewCodeBlockMessage(fmt.Sprintf("New issue created successfully! 🎉\n\nIssue URL: %s", issueURL), false),
}, nil
}

Expand Down
10 changes: 6 additions & 4 deletions cmd/source/cm-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ func (CMWatcher) Stream(ctx context.Context, in source.StreamInput) (source.Stre
}

out := source.StreamOutput{
Output: make(chan []byte),
Event: make(chan source.Event),
}

go listenEvents(ctx, in.Context.KubeConfig, cfg.ConfigMap, out.Output)
go listenEvents(ctx, in.Context.KubeConfig, cfg.ConfigMap, out.Event)

return out, nil
}

func listenEvents(ctx context.Context, kubeConfig []byte, obj Object, sink chan<- []byte) {
func listenEvents(ctx context.Context, kubeConfig []byte, obj Object, sink chan source.Event) {
config, err := clientcmd.RESTConfigFromKubeConfig(kubeConfig)
exitOnError(err)
clientset, err := kubernetes.NewForConfig(config)
Expand All @@ -102,7 +102,9 @@ func listenEvents(ctx context.Context, kubeConfig []byte, obj Object, sink chan<
if event.Type == obj.Event {
cm := event.Object.(*corev1.ConfigMap)
msg := fmt.Sprintf("Plugin %s detected `%s` event on `%s/%s`", pluginName, obj.Event, cm.Namespace, cm.Name)
sink <- []byte(msg)
sink <- source.Event{
Message: api.NewPlaintextMessage(msg, true),
}
}

// always continue - context will cancel this watch for us :)
Expand Down
6 changes: 3 additions & 3 deletions hack/gen-grpc-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ REPO_ROOT_DIR=$(cd "${CURRENT_DIR}/.." && pwd)
readonly CURRENT_DIR
readonly REPO_ROOT_DIR

readonly STABLE_PROTOC_VERSION=3.20.2
readonly STABLE_PROTOC_GEN_GO_GRPC_VERSION=1.2.0
readonly STABLE_PROTOC_GEN_GO_VERSION=v1.27.1
readonly STABLE_PROTOC_VERSION=24.0
readonly STABLE_PROTOC_GEN_GO_GRPC_VERSION=1.3.0
readonly STABLE_PROTOC_GEN_GO_VERSION=v1.31.0

readonly GREEN='\033[0;32m'
readonly NC='\033[0m' # No Color
Expand Down
1 change: 0 additions & 1 deletion internal/executor/helm/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func TestExecutorHelmInstallFlagsErrors(t *testing.T) {
// then
require.EqualError(t, err, tc.expErrMsg)
assert.Empty(t, out.Message)
assert.Empty(t, out.Data)
})
}
}
Expand Down
21 changes: 0 additions & 21 deletions internal/source/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/kubeshop/botkube/internal/audit"
"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/pkg/action"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/source"
"github.com/kubeshop/botkube/pkg/bot"
"github.com/kubeshop/botkube/pkg/bot/interactive"
Expand Down Expand Up @@ -123,12 +122,6 @@ func (d *Dispatcher) Dispatch(dispatch PluginDispatch) error {
go func() {
for {
select {
case event, ok := <-out.Output:
if !ok {
return
}
log.WithField("event", string(event)).Debug("Dispatching received event...")
d.dispatch(ctx, event, dispatch)
case msg, ok := <-out.Event:
if !ok {
return
Expand Down Expand Up @@ -232,20 +225,6 @@ func (d *Dispatcher) dispatchMsg(ctx context.Context, event source.Event, dispat
}
}

func (d *Dispatcher) dispatch(ctx context.Context, event []byte, dispatch PluginDispatch) {
if event == nil {
return
}

d.dispatchMsg(ctx, source.Event{
Message: api.Message{
BaseBody: api.Body{
Plaintext: string(event),
},
},
}, dispatch)
}

func (d *Dispatcher) reportAuditEvent(ctx context.Context, pluginName string, event any, sourceName, sourceDisplayName string) error {
eventBytes, err := json.Marshal(event)
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions internal/source/kubernetes/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import (
type Event struct {
APIVersion string
Kind string
Code string
Title string
Name string
Namespace string
Messages []string
Type config.EventType
Reason string
Error string
Level config.Level
Cluster string
TimeStamp time.Time
Expand All @@ -34,7 +32,6 @@ type Event struct {
Resource string
Recommendations []string
Warnings []string
Actions []Action

// The following fields are ignored when marshalling the event by purpose.
// We send the whole Event struct via sink.Elasticsearch integration.
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/cloudslack/cloudslack.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions pkg/api/cloudslack/cloudslack_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 54 additions & 63 deletions pkg/api/executor/executor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading