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

Migrate disabled plugins to Cloud #1355

Merged
merged 4 commits into from
Jan 24, 2024
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
242 changes: 121 additions & 121 deletions helm/botkube/README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ executors:
## Helm executor configuration
## Plugin name syntax: <repo>/<plugin>[@<version>]. If version is not provided, the latest version from repository is used.
botkube/helm:
displayName: "Helm"
# -- If true, enables `helm` commands execution.
enabled: false
config:
Expand All @@ -616,6 +617,7 @@ executors:
## Kubectl executor configuration
## Plugin name syntax: <repo>/<plugin>[@<version>]. If version is not provided, the latest version from repository is used.
botkube/kubectl:
displayName: "Kubectl"
enabled: false
# -- Custom kubectl configuration.
# @default -- See the `values.yaml` file for full object including optional properties related to interactive builder.
Expand All @@ -642,6 +644,7 @@ executors:
## Exec executor configuration.
## Plugin name syntax: <repo>/<plugin>[@<version>]. If version is not provided, the latest version from repository is used.
botkube/exec:
displayName: "Exec"
enabled: false
context: *default-plugin-context
## -- Custom exec plugin configuration.
Expand All @@ -657,6 +660,7 @@ executors:
## Doctor executor configuration.
## Plugin name syntax: <repo>/<plugin>[@<version>]. If version is not provided, the latest version from repository is used.
botkube/doctor:
displayName: "Doctor AI"
enabled: false
context: *default-plugin-context
## -- Custom doctor plugin configuration.
Expand All @@ -679,6 +683,7 @@ executors:
# Flux executor configuration.
## Plugin name syntax: <repo>/<plugin>[@<version>]. If version is not provided, the latest version from repository is used.
botkube/flux:
displayName: "Flux"
enabled: false
context:
rbac:
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/install/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package helm

import (
"context"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -75,9 +74,10 @@ func (c *Helm) Install(ctx context.Context, status *printer.StatusPrinter, opts
if err != nil {
return nil, fmt.Errorf("while confiriming upgrade: %v", err)
}

if !upgrade {
return nil, errors.New("upgrade aborted")
status.Step("Skipped Botkube installation upgrade.")
status.End(true)
return nil, nil
}
}
restartAnnotation := fmt.Sprintf(restartAnnotationFmt, time.Now().Unix())
Expand Down
5 changes: 5 additions & 0 deletions internal/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func Install(ctx context.Context, w io.Writer, k8sCfg *kubex.ConfigWithMeta, opt
if err != nil {
return err
}
if rel == nil {
//There wasn't any errors and we don't have release.
//User answered "no" on prompt: Do you want to upgrade existing installation?
return nil
}

if opts.HelmParams.DryRun {
return printSuccessInstallMessage(opts.HelmParams.Version, w)
Expand Down
28 changes: 24 additions & 4 deletions internal/cli/migrate/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,23 @@ func (c *Converter) convertExecutors(executors map[string]bkconfig.Executors) ([
errs := multierror.New()
for cfgName, conf := range executors {
for name, p := range conf.Plugins {
if !p.Enabled || !strings.HasPrefix(name, "botkube") { // skip all 3rd party plugins
if !strings.HasPrefix(name, "botkube") { // skip all 3rd party plugins
continue
}

rawCfg, err := json.Marshal(p.Config)
if err != nil {
return nil, err
}
displayName := conf.DisplayName
if displayName == "" {
displayName = name
}
out = append(out, &gqlModel.PluginConfigurationGroupInput{
Name: name,
DisplayName: name,
DisplayName: displayName,
Type: gqlModel.PluginTypeExecutor,
Enabled: p.Enabled,
Configurations: []*gqlModel.PluginConfigurationInput{
{
Name: c.getOrGeneratePluginName(cfgName),
Expand All @@ -138,17 +143,22 @@ func (c *Converter) convertSources(sources map[string]bkconfig.Sources) ([]*gqlM
errs := multierror.New()
for cfgName, conf := range sources {
for name, p := range conf.Plugins {
if !p.Enabled || !strings.HasPrefix(name, "botkube") { // skip all 3rd party plugins
if !strings.HasPrefix(name, "botkube") { // skip all 3rd party plugins
continue
}
rawCfg, err := json.Marshal(p.Config)
if err != nil {
return nil, err
}
displayName := conf.DisplayName
if displayName == "" {
displayName = name
}
out = append(out, &gqlModel.PluginConfigurationGroupInput{
Name: name,
DisplayName: conf.DisplayName,
DisplayName: displayName,
Type: gqlModel.PluginTypeSource,
Enabled: p.Enabled,
Configurations: []*gqlModel.PluginConfigurationInput{
{
Name: c.getOrGeneratePluginName(cfgName),
Expand All @@ -164,6 +174,16 @@ func (c *Converter) convertSources(sources map[string]bkconfig.Sources) ([]*gqlM
}

func (c *Converter) convertRbac(ctx bkconfig.PluginContext) *gqlModel.RBACInput {
if ctx.RBAC == nil {
return &gqlModel.RBACInput{
User: &gqlModel.UserPolicySubjectInput{
Type: gqlModel.PolicySubjectTypeEmpty,
},
Group: &gqlModel.GroupPolicySubjectInput{
Type: gqlModel.PolicySubjectTypeEmpty,
},
}
}
return &gqlModel.RBACInput{
User: &gqlModel.UserPolicySubjectInput{
Type: graphqlPolicySubjectType(ctx.RBAC.User.Type),
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ const (

// Executors contains executors configuration parameters.
type Executors struct {
Plugins Plugins `yaml:",inline" koanf:",remain"`
DisplayName string `yaml:"displayName"`
Plugins Plugins `yaml:",inline" koanf:",remain"`
}

// CollectCommandPrefixes returns list of command prefixes for all executors, even disabled ones.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ sources:
context: {}
executors:
echo:
displayName: Echo
botkube/echo:
enabled: true
config:
changeResponseToUpperCase: true
context: {}
k8s-tools:
displayName: K8S Tools
botkube/helm:
enabled: true
config: null
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/testdata/TestLoadConfigSuccess/executors.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
executors:
'k8s-tools':
displayName: K8S Tools
botkube/kubectl:
enabled: true
botkube/helm:
enabled: true
'echo':
displayName: Echo
botkube/echo:
enabled: true
config:
Expand Down
Loading