diff --git a/cmd/executor/gh/main.go b/cmd/executor/gh/main.go index b8eb47251a..bbf1c7dedb 100644 --- a/cmd/executor/gh/main.go +++ b/cmd/executor/gh/main.go @@ -60,6 +60,10 @@ func (*GHExecutor) Metadata(context.Context) (api.MetadataOutput, error) { // Execute returns a given command as a response. func (e *GHExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) { + if err := pluginx.CheckKubeConfigProvided(pluginName, in.Context.KubeConfig); err != nil { + return executor.ExecuteOutput{}, err + } + var cfg Config err := pluginx.MergeExecutorConfigs(in.Configs, &cfg) if err != nil { diff --git a/internal/executor/helm/executor.go b/internal/executor/helm/executor.go index a7843cde60..5c72dbcf20 100644 --- a/internal/executor/helm/executor.go +++ b/internal/executor/helm/executor.go @@ -84,6 +84,10 @@ func (e *Executor) Metadata(context.Context) (api.MetadataOutput, error) { // - history // - get [all|manifest|hooks|notes] func (e *Executor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) { + if err := pluginx.CheckKubeConfigProvided(PluginName, in.Context.KubeConfig); err != nil { + return executor.ExecuteOutput{}, err + } + cfg, err := MergeConfigs(in.Configs) if err != nil { return executor.ExecuteOutput{}, fmt.Errorf("while merging input configs: %w", err) diff --git a/internal/executor/helm/executor_test.go b/internal/executor/helm/executor_test.go index ce00bae9b6..a8ae07676a 100644 --- a/internal/executor/helm/executor_test.go +++ b/internal/executor/helm/executor_test.go @@ -226,6 +226,9 @@ func TestExecutorConfigMergingErrors(t *testing.T) { // when _, err := hExec.Execute(context.Background(), executor.ExecuteInput{ Command: "helm install", + Context: executor.ExecuteInputContext{ + KubeConfig: []byte("fake config"), + }, Configs: []*executor.Config{ { RawYAML: mustYAMLMarshal(t, configA), diff --git a/internal/executor/kubectl/executor.go b/internal/executor/kubectl/executor.go index 54e4cb3ab0..c43bb3545f 100644 --- a/internal/executor/kubectl/executor.go +++ b/internal/executor/kubectl/executor.go @@ -74,6 +74,10 @@ func (e *Executor) Metadata(context.Context) (api.MetadataOutput, error) { // Execute returns a given command as response. func (e *Executor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) { + if err := pluginx.CheckKubeConfigProvided(PluginName, in.Context.KubeConfig); err != nil { + return executor.ExecuteOutput{}, err + } + cfg, err := MergeConfigs(in.Configs) if err != nil { return executor.ExecuteOutput{}, fmt.Errorf("while merging input configs: %w", err) diff --git a/internal/source/dispatcher.go b/internal/source/dispatcher.go index 874d6e6bd2..ac736eb486 100644 --- a/internal/source/dispatcher.go +++ b/internal/source/dispatcher.go @@ -115,7 +115,7 @@ func (d *Dispatcher) Dispatch(dispatch PluginDispatch) error { }, }) if err != nil { - return fmt.Errorf("while opening stream for %s: %w", dispatch.pluginName, err) + return fmt.Errorf(`while opening stream for "%s.%s" source: %w`, dispatch.sourceName, dispatch.pluginName, err) } go func() { diff --git a/internal/source/kubernetes/source.go b/internal/source/kubernetes/source.go index f85155e0ae..73c44f68ea 100644 --- a/internal/source/kubernetes/source.go +++ b/internal/source/kubernetes/source.go @@ -24,6 +24,7 @@ import ( "github.com/kubeshop/botkube/pkg/api" "github.com/kubeshop/botkube/pkg/api/source" pkgConfig "github.com/kubeshop/botkube/pkg/config" + "github.com/kubeshop/botkube/pkg/pluginx" ) const ( @@ -64,6 +65,10 @@ func NewSource(version string) *Source { // Stream streams Kubernetes events func (*Source) Stream(ctx context.Context, input source.StreamInput) (source.StreamOutput, error) { + if err := pluginx.CheckKubeConfigProvided(PluginName, input.Context.KubeConfig); err != nil { + return source.StreamOutput{}, err + } + cfg, err := config.MergeConfigs(input.Configs) if err != nil { return source.StreamOutput{}, fmt.Errorf("while merging input configs: %w", err) diff --git a/pkg/pluginx/kubeconfig.go b/pkg/pluginx/kubeconfig.go index 98f6ac9b41..3a0b54b192 100644 --- a/pkg/pluginx/kubeconfig.go +++ b/pkg/pluginx/kubeconfig.go @@ -9,7 +9,7 @@ import ( "github.com/pkg/errors" ) -func PersistKubeConfig(ctx context.Context, kc []byte) (string, func(context.Context) error, error) { +func PersistKubeConfig(_ context.Context, kc []byte) (string, func(context.Context) error, error) { if len(kc) == 0 { return "", nil, fmt.Errorf("received empty kube config") } @@ -34,3 +34,11 @@ func PersistKubeConfig(ctx context.Context, kc []byte) (string, func(context.Con return abs, deleteFn, nil } + +// CheckKubeConfigProvided returns an error if a given kubeconfig is empty or nil. +func CheckKubeConfigProvided(pluginName string, kubeconfig []byte) error { + if len(kubeconfig) != 0 { + return nil + } + return fmt.Errorf("The kubeconfig data is missing. Please make sure that you have specified a valid RBAC configuration for %q plugin. Learn more at https://docs.botkube.io/configuration/rbac.", pluginName) +}