Skip to content

Commit

Permalink
Migrate disabled plugins to Cloud (#1355)
Browse files Browse the repository at this point in the history
* ADD migrate for disabled plugin
MOD improve RBAC conversion
FIX installation command abort

* Update golden files

* FIX CR

* MOD helm chart docs
  • Loading branch information
madebyrogal authored Jan 24, 2024
1 parent 29d024c commit 69b9cc7
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 129 deletions.
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
2 changes: 2 additions & 0 deletions pkg/config/testdata/TestLoadConfigSuccess/config.golden.yaml
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

0 comments on commit 69b9cc7

Please sign in to comment.