Skip to content

Commit

Permalink
Move internal/plugin to pkg (#1383)
Browse files Browse the repository at this point in the history
* Move internal/plugin to pkg/plugin
* Fix gitignore
  • Loading branch information
pkosiec authored Feb 19, 2024
1 parent bc62399 commit a5f9e07
Show file tree
Hide file tree
Showing 90 changed files with 197 additions and 214 deletions.
2 changes: 1 addition & 1 deletion cmd/botkube-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/kubeshop/botkube/internal/heartbeat"
"github.com/kubeshop/botkube/internal/insights"
"github.com/kubeshop/botkube/internal/kubex"
"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/internal/source"
"github.com/kubeshop/botkube/internal/status"
"github.com/kubeshop/botkube/internal/storage"
Expand All @@ -47,6 +46,7 @@ import (
"github.com/kubeshop/botkube/pkg/maputil"
"github.com/kubeshop/botkube/pkg/multierror"
"github.com/kubeshop/botkube/pkg/notifier"
"github.com/kubeshop/botkube/pkg/plugin"
"github.com/kubeshop/botkube/pkg/sink"
"github.com/kubeshop/botkube/pkg/version"
)
Expand Down
8 changes: 4 additions & 4 deletions cmd/executor/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"fmt"
"strings"

"github.com/hashicorp/go-plugin"
goplugin "github.com/hashicorp/go-plugin"

"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

var (
Expand Down Expand Up @@ -51,7 +51,7 @@ func (*EchoExecutor) Metadata(context.Context) (api.MetadataOutput, error) {
// Execute returns a given command as response.
func (*EchoExecutor) Execute(_ context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {
var cfg Config
err := pluginx.MergeExecutorConfigs(in.Configs, &cfg)
err := plugin.MergeExecutorConfigs(in.Configs, &cfg)
if err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while merging input configuration: %w", err)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (*EchoExecutor) Help(context.Context) (api.Message, error) {
}

func main() {
executor.Serve(map[string]plugin.Plugin{
executor.Serve(map[string]goplugin.Plugin{
pluginName: &executor.Plugin{
Executor: &EchoExecutor{},
},
Expand Down
14 changes: 7 additions & 7 deletions cmd/executor/exec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/alexflint/go-arg"
"github.com/hashicorp/go-plugin"
goplugin "github.com/hashicorp/go-plugin"
"github.com/sirupsen/logrus"

"github.com/kubeshop/botkube/internal/executor/x"
Expand All @@ -18,7 +18,7 @@ import (
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/formatx"
"github.com/kubeshop/botkube/pkg/loggerx"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

// version is set via ldflags by GoReleaser.
Expand Down Expand Up @@ -89,7 +89,7 @@ func escapePositionals(in string) string {
func (i *XExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {
var cmd Commands
in.Command = escapePositionals(in.Command)
err := pluginx.ParseCommand(pluginName, in.Command, &cmd)
err := plugin.ParseCommand(pluginName, in.Command, &cmd)
switch err {
case nil:
case arg.ErrHelp:
Expand All @@ -106,7 +106,7 @@ func (i *XExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (exec
{Ref: getDefaultTemplateSource()},
},
}
if err := pluginx.MergeExecutorConfigs(in.Configs, &cfg); err != nil {
if err := plugin.MergeExecutorConfigs(in.Configs, &cfg); err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while merging configs: %v", err)
}

Expand Down Expand Up @@ -166,7 +166,7 @@ func (i *XExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (exec
"runCommand": downloadCmd,
}).Info("Installing binary...")

if _, err := pluginx.ExecuteCommand(ctx, downloadCmd, pluginx.ExecuteCommandEnvs(map[string]string{
if _, err := plugin.ExecuteCommand(ctx, downloadCmd, plugin.ExecuteCommandEnvs(map[string]string{
"EGET_BIN": dir,
})); err != nil {
return "", err
Expand All @@ -186,7 +186,7 @@ func (i *XExecutor) getKubeconfig(ctx context.Context, log logrus.FieldLogger, i
if len(in.Context.KubeConfig) == 0 {
return "", func() {}, nil
}
kubeConfigPath, deleteFn, err := pluginx.PersistKubeConfig(ctx, in.Context.KubeConfig)
kubeConfigPath, deleteFn, err := plugin.PersistKubeConfig(ctx, in.Context.KubeConfig)
if err != nil {
return "", func() {}, fmt.Errorf("while writing kubeconfig file: %w", err)
}
Expand All @@ -200,7 +200,7 @@ func (i *XExecutor) getKubeconfig(ctx context.Context, log logrus.FieldLogger, i
}

func main() {
executor.Serve(map[string]plugin.Plugin{
executor.Serve(map[string]goplugin.Plugin{
pluginName: &executor.Plugin{
Executor: &XExecutor{},
},
Expand Down
20 changes: 10 additions & 10 deletions cmd/executor/gh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"fmt"
"text/template"

"github.com/hashicorp/go-plugin"
goplugin "github.com/hashicorp/go-plugin"

"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/loggerx"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

const (
Expand Down Expand Up @@ -74,18 +74,18 @@ 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.ValidateKubeConfigProvided(pluginName, in.Context.KubeConfig); err != nil {
if err := plugin.ValidateKubeConfigProvided(pluginName, in.Context.KubeConfig); err != nil {
return executor.ExecuteOutput{}, err
}

var cfg Config
err := pluginx.MergeExecutorConfigs(in.Configs, &cfg)
err := plugin.MergeExecutorConfigs(in.Configs, &cfg)
if err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while merging input configs: %w", err)
}

var cmd Commands
err = pluginx.ParseCommand(pluginName, in.Command, &cmd)
err = plugin.ParseCommand(pluginName, in.Command, &cmd)
if err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while parsing input command: %w", err)
}
Expand All @@ -98,7 +98,7 @@ func (e *GHExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (exe

log := loggerx.New(cfg.Log)

kubeConfigPath, deleteFn, err := pluginx.PersistKubeConfig(ctx, in.Context.KubeConfig)
kubeConfigPath, deleteFn, err := plugin.PersistKubeConfig(ctx, in.Context.KubeConfig)
if err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while writing kubeconfig file: %w", err)
}
Expand Down Expand Up @@ -159,7 +159,7 @@ var depsDownloadLinks = map[string]api.Dependency{
}

func main() {
executor.Serve(map[string]plugin.Plugin{
executor.Serve(map[string]goplugin.Plugin{
pluginName: &executor.Plugin{
Executor: &GHExecutor{},
},
Expand All @@ -173,7 +173,7 @@ func createGitHubIssue(cfg Config, title, mdBody string) (string, error) {
"GH_TOKEN": cfg.GitHub.Token,
}

output, err := pluginx.ExecuteCommand(context.Background(), cmd, pluginx.ExecuteCommandEnvs(envs))
output, err := plugin.ExecuteCommand(context.Background(), cmd, plugin.ExecuteCommandEnvs(envs))
if err != nil {
return "", err
}
Expand All @@ -193,11 +193,11 @@ func getIssueDetails(ctx context.Context, namespace, name, kubeConfigPath string
namespace = defaultNamespace
}

logs, err := pluginx.ExecuteCommand(ctx, fmt.Sprintf("kubectl --kubeconfig=%s logs %s -n %s --tail %d", kubeConfigPath, name, namespace, logsTailLines))
logs, err := plugin.ExecuteCommand(ctx, fmt.Sprintf("kubectl --kubeconfig=%s logs %s -n %s --tail %d", kubeConfigPath, name, namespace, logsTailLines))
if err != nil {
return IssueDetails{}, fmt.Errorf("while getting logs: %w", err)
}
ver, err := pluginx.ExecuteCommand(ctx, fmt.Sprintf("kubectl --kubeconfig=%s version -o yaml", kubeConfigPath))
ver, err := plugin.ExecuteCommand(ctx, fmt.Sprintf("kubectl --kubeconfig=%s version -o yaml", kubeConfigPath))
if err != nil {
return IssueDetails{}, fmt.Errorf("while getting version: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/executor/thread-mate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"sync"

"github.com/alexflint/go-arg"
"github.com/hashicorp/go-plugin"
goplugin "github.com/hashicorp/go-plugin"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

thmate "github.com/kubeshop/botkube/internal/executor/thread-mate"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

const pluginName = "thread-mate"
Expand Down Expand Up @@ -67,12 +67,12 @@ func (t *ThreadMateExecutor) init(cfg thmate.Config, kubeconfig []byte) (*thmate

// Execute returns a given command as a response.
func (t *ThreadMateExecutor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {
if err := pluginx.ValidateKubeConfigProvided(pluginName, in.Context.KubeConfig); err != nil {
if err := plugin.ValidateKubeConfigProvided(pluginName, in.Context.KubeConfig); err != nil {
return executor.ExecuteOutput{}, err
}

var cmd thmate.Commands
err := pluginx.ParseCommand(pluginName, in.Command, &cmd)
err := plugin.ParseCommand(pluginName, in.Command, &cmd)
switch {
case err == nil:
case errors.Is(err, arg.ErrHelp):
Expand Down Expand Up @@ -151,7 +151,7 @@ func (*ThreadMateExecutor) Help(context.Context) (api.Message, error) {
}

func main() {
executor.Serve(map[string]plugin.Plugin{
executor.Serve(map[string]goplugin.Plugin{
pluginName: &executor.Plugin{
Executor: NewThreadMateExecutor(),
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/source/cm-watcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"log"

"github.com/hashicorp/go-plugin"
goplugin "github.com/hashicorp/go-plugin"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand All @@ -20,7 +20,7 @@ import (

"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/source"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

var (
Expand Down Expand Up @@ -84,7 +84,7 @@ func (CMWatcher) Metadata(_ context.Context) (api.MetadataOutput, error) {
// Stream sends an event when a given ConfigMap is matched against the criteria defined in config.
func (CMWatcher) Stream(ctx context.Context, in source.StreamInput) (source.StreamOutput, error) {
var cfg Config
err := pluginx.MergeSourceConfigsWithDefaults(defaultConfig, in.Configs, &cfg)
err := plugin.MergeSourceConfigsWithDefaults(defaultConfig, in.Configs, &cfg)
if err != nil {
return source.StreamOutput{}, fmt.Errorf("while merging input configuration: %w", err)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func listenEvents(ctx context.Context, kubeConfig []byte, obj Object, sink chan
}

func main() {
source.Serve(map[string]plugin.Plugin{
source.Serve(map[string]goplugin.Plugin{
pluginName: &source.Plugin{
Source: &CMWatcher{},
},
Expand Down
2 changes: 1 addition & 1 deletion hack/gen-plugin-index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"path/filepath"

"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/pkg/loggerx"
"github.com/kubeshop/botkube/pkg/plugin"

"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
Expand Down
2 changes: 1 addition & 1 deletion internal/analytics/segment_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"k8s.io/client-go/kubernetes"

"github.com/kubeshop/botkube/internal/analytics/batched"
"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/plugin"
"github.com/kubeshop/botkube/pkg/ptr"
"github.com/kubeshop/botkube/pkg/version"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/executor/doctor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/loggerx"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

const (
Expand Down Expand Up @@ -75,7 +75,7 @@ func (d *Executor) Metadata(context.Context) (api.MetadataOutput, error) {
// Execute returns a given command as a response.
func (d *Executor) Execute(ctx context.Context, in executor.ExecuteInput) (executor.ExecuteOutput, error) {
var cfg Config
err := pluginx.MergeExecutorConfigs(in.Configs, &cfg)
err := plugin.MergeExecutorConfigs(in.Configs, &cfg)
if err != nil {
return executor.ExecuteOutput{}, fmt.Errorf("while merging input configuration: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/executor/flux/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/kubeshop/botkube/pkg/formatx"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

// deleteConfirmPhase represent a confirmation phase for deletion. Taken from flux: v2.0.1.
Expand Down Expand Up @@ -38,9 +38,9 @@ func normalize(in string) string {
}

// ExecuteCommand is a syntax sugar for running CLI commands.
func ExecuteCommand(ctx context.Context, in string, opts ...pluginx.ExecuteCommandMutation) (string, error) {
opts = append(opts, pluginx.ExecuteClearColorCodes())
out, err := pluginx.ExecuteCommand(ctx, in, opts...)
func ExecuteCommand(ctx context.Context, in string, opts ...plugin.ExecuteCommandMutation) (string, error) {
opts = append(opts, plugin.ExecuteClearColorCodes())
out, err := plugin.ExecuteCommand(ctx, in, opts...)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/executor/flux/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package flux

import (
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/pluginx"
"github.com/kubeshop/botkube/pkg/plugin"
)

// Config holds Flux executor configuration.
Expand All @@ -18,5 +18,5 @@ type Config struct {
} `yaml:"github"`

// Fields not exposed to the user in the JSON schema
TmpDir pluginx.TmpDir `yaml:"tmpDir"`
TmpDir plugin.TmpDir `yaml:"tmpDir"`
}
Loading

0 comments on commit a5f9e07

Please sign in to comment.