forked from kubeshop/botkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
344 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/kubeshop/botkube/internal/cli" | ||
"github.com/kubeshop/botkube/internal/cli/heredoc" | ||
"github.com/kubeshop/botkube/internal/cli/install" | ||
"github.com/kubeshop/botkube/internal/cli/uninstall" | ||
"github.com/kubeshop/botkube/internal/kubex" | ||
) | ||
|
||
// NewUninstall returns a cobra.Command for deleting Botkube Helm release. | ||
func NewUninstall() *cobra.Command { | ||
var opts uninstall.Config | ||
|
||
uninstallCmd := &cobra.Command{ | ||
Use: "uninstall [OPTIONS]", | ||
Short: "uninstall Botkube from cluster", | ||
Long: "Use this command to uninstall the Botkube agent.", | ||
Aliases: []string{"uninstall", "del", "delete", "un"}, | ||
Example: heredoc.WithCLIName(` | ||
# Uninstall latest stable Botkube version | ||
<cli> uninstall | ||
<cli> install --repo @local`, cli.Name), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
config, err := kubex.LoadRestConfigWithMetaInformation() | ||
if err != nil { | ||
return err | ||
} | ||
if err != nil { | ||
return errors.Wrap(err, "while creating k8s config") | ||
} | ||
|
||
return uninstall.Uninstall(cmd.Context(), os.Stdout, config, opts) | ||
}, | ||
} | ||
|
||
flags := uninstallCmd.Flags() | ||
|
||
kubex.RegisterKubeconfigFlag(flags) | ||
|
||
flags.StringVar(&opts.HelmParams.ReleaseName, "release-name", install.ReleaseName, "Botkube Helm release name.") | ||
flags.StringVar(&opts.HelmParams.ReleaseNamespace, "namespace", install.Namespace, "Botkube namespace.") | ||
|
||
flags.BoolVar(&opts.HelmParams.DryRun, "dry-run", false, "simulate a uninstall") | ||
flags.BoolVar(&opts.HelmParams.DisableHooks, "no-hooks", false, "prevent hooks from running during uninstallation") | ||
flags.BoolVar(&opts.HelmParams.KeepHistory, "keep-history", false, "remove all associated resources and mark the release as deleted, but retain the release history") | ||
flags.BoolVar(&opts.HelmParams.Wait, "wait", true, "if set, will wait until all the resources are deleted before returning. It will wait for as long as --timeout") | ||
flags.StringVar(&opts.HelmParams.DeletionPropagation, "cascade", "background", "Must be \"background\", \"orphan\", or \"foreground\". Selects the deletion cascading strategy for the dependents. Defaults to background.") | ||
flags.DurationVar(&opts.HelmParams.Timeout, "timeout", 300*time.Second, "time to wait for any individual Kubernetes operation (like Jobs for hooks)") | ||
flags.StringVar(&opts.HelmParams.Description, "description", "", "add a custom description") | ||
|
||
return uninstallCmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: botkube uninstall | ||
--- | ||
|
||
## botkube uninstall | ||
|
||
uninstall Botkube from cluster | ||
|
||
### Synopsis | ||
|
||
Use this command to uninstall the Botkube agent. | ||
|
||
``` | ||
botkube uninstall [OPTIONS] [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
# Uninstall latest stable Botkube version | ||
botkube uninstall | ||
botkube install --repo @local | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--cascade string Must be "background", "orphan", or "foreground". Selects the deletion cascading strategy for the dependents. Defaults to background. (default "background") | ||
--description string add a custom description | ||
--dry-run simulate a uninstall | ||
-h, --help help for uninstall | ||
--keep-history remove all associated resources and mark the release as deleted, but retain the release history | ||
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster. | ||
--namespace string Botkube namespace. (default "botkube") | ||
--no-hooks prevent hooks from running during uninstallation | ||
--release-name string Botkube Helm release name. (default "botkube") | ||
--timeout duration time to wait for any individual Kubernetes operation (like Jobs for hooks) (default 5m0s) | ||
--wait if set, will wait until all the resources are deleted before returning. It will wait for as long as --timeout (default true) | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
-v, --verbose int/string[=simple] Prints more verbose output. Allowed values: 0 - disable, 1 - simple, 2 - trace (default 0 - disable) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [botkube](botkube.md) - Botkube CLI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package helmx | ||
|
||
import ( | ||
"fmt" | ||
|
||
"helm.sh/helm/v3/pkg/action" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"k8s.io/client-go/rest" | ||
|
||
"github.com/kubeshop/botkube/internal/cli" | ||
"github.com/kubeshop/botkube/internal/ptr" | ||
) | ||
|
||
const helmDriver = "secrets" | ||
|
||
// GetActionConfiguration returns generic configuration for Helm actions. | ||
func GetActionConfiguration(k8sCfg *rest.Config, forNamespace string) (*action.Configuration, error) { | ||
actionConfig := new(action.Configuration) | ||
helmCfg := &genericclioptions.ConfigFlags{ | ||
APIServer: &k8sCfg.Host, | ||
Insecure: &k8sCfg.Insecure, | ||
CAFile: &k8sCfg.CAFile, | ||
BearerToken: &k8sCfg.BearerToken, | ||
Namespace: ptr.FromType(forNamespace), | ||
} | ||
|
||
debugLog := func(format string, v ...interface{}) { | ||
if cli.VerboseMode.IsTracing() { | ||
fmt.Print(" Helm log: ") // if enabled, we need to nest that under Helm step which was already printed with 2 spaces. | ||
fmt.Printf(format, v...) | ||
fmt.Println() | ||
} | ||
} | ||
|
||
err := actionConfig.Init(helmCfg, forNamespace, helmDriver, debugLog) | ||
if err != nil { | ||
return nil, fmt.Errorf("while initializing Helm configuration: %v", err) | ||
} | ||
|
||
return actionConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package uninstall | ||
|
||
import "github.com/kubeshop/botkube/internal/cli/uninstall/helm" | ||
|
||
// Config holds parameters for Botkube deletion. | ||
type Config struct { | ||
HelmParams helm.Config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package helm | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Config holds Helm configuration parameters. | ||
type Config struct { | ||
ReleaseName string | ||
ReleaseNamespace string | ||
|
||
DisableHooks bool | ||
DryRun bool | ||
KeepHistory bool | ||
Wait bool | ||
DeletionPropagation string | ||
Timeout time.Duration | ||
Description string | ||
} |
Oops, something went wrong.