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

Add option to install Botkube via CLI, add --verbose flag #1134

Merged
merged 4 commits into from
Jul 12, 2023
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
83 changes: 83 additions & 0 deletions cmd/cli/cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package cmd

import (
"fmt"
"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/kubex"
)

// NewInstall returns a cobra.Command for installing Botkube.
func NewInstall() *cobra.Command {
var opts install.Config

installCmd := &cobra.Command{
Use: "install [OPTIONS]",
Short: "install Botkube into cluster",
Long: "Use this command to install the Botkube agent.",
Example: heredoc.WithCLIName(`
# Install latest stable Botkube version
<cli> install

# Install Botkube 0.1.0 version
<cli> install --version 0.1.0

# Install Botkube from local git repository. Needs to be run from the main directory.
<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 install.Install(cmd.Context(), os.Stdout, config, opts)
},
}

flags := installCmd.Flags()

kubex.RegisterKubeconfigFlag(flags)

// common params for install and upgrade operation
flags.StringVar(&opts.HelmParams.Version, "version", install.LatestVersionTag, "Botkube version. Possible values @latest, 1.2.0, ...")
flags.StringVar(&opts.HelmParams.Namespace, "namespace", install.Namespace, "Botkube installation namespace.")
flags.StringVar(&opts.HelmParams.ReleaseName, "release-name", install.ReleaseName, "Botkube Helm chart release name.")
flags.StringVar(&opts.HelmParams.ChartName, "chart-name", "botkube", "Botkube Helm chart name.")
flags.StringVar(&opts.HelmParams.RepoLocation, "repo", install.HelmRepoStable, fmt.Sprintf("Botkube Helm chart repository location. It can be relative path to current working directory or URL. Use %s tag to select repository which holds the stable Helm chart versions.", install.StableVersionTag))
flags.BoolVar(&opts.HelmParams.DryRun, "dry-run", false, "Simulate an install")
flags.BoolVar(&opts.HelmParams.Force, "force", false, "Force resource updates through a replacement strategy")
flags.BoolVar(&opts.HelmParams.DisableHooks, "no-hooks", false, "Disable pre/post install/upgrade hooks")
flags.BoolVar(&opts.HelmParams.DisableOpenAPIValidation, "disable-openapi-validation", false, "If set, it will not validate rendered templates against the Kubernetes OpenAPI Schema")
flags.BoolVar(&opts.HelmParams.SkipCRDs, "skip-crds", false, "If set, no CRDs will be installed.")
flags.DurationVar(&opts.HelmParams.Timeout, "timeout", 5*time.Minute, "time to wait for any individual Kubernetes operation (like Jobs for hooks)")
flags.BoolVar(&opts.HelmParams.Wait, "wait", true, "If set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout")
flags.BoolVar(&opts.HelmParams.WaitForJobs, "wait-for-jobs", true, "If set and --wait enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as --timeout")
flags.BoolVar(&opts.HelmParams.Atomic, "atomic", false, "If set, process rolls back changes made in case of failed install/upgrade. The --wait flag will be set automatically if --atomic is used")
flags.BoolVar(&opts.HelmParams.SubNotes, "render-subchart-notes", false, "If set, render subchart notes along with the parent")
flags.StringVar(&opts.HelmParams.Description, "description", "", "add a custom description")
flags.BoolVar(&opts.HelmParams.DependencyUpdate, "dependency-update", false, "Update dependencies if they are missing before installing the chart")

// custom values settings
flags.StringSliceVarP(&opts.HelmParams.Values.ValueFiles, "values", "f", []string{}, "Specify values in a YAML file or a URL (can specify multiple)")
flags.StringArrayVar(&opts.HelmParams.Values.Values, "set", []string{}, "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
flags.StringArrayVar(&opts.HelmParams.Values.StringValues, "set-string", []string{}, "Set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
flags.StringArrayVar(&opts.HelmParams.Values.FileValues, "set-file", []string{}, "Set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)")
flags.StringArrayVar(&opts.HelmParams.Values.JSONValues, "set-json", []string{}, "Set JSON values on the command line (can specify multiple or separate values with commas: key1=jsonval1,key2=jsonval2)")
flags.StringArrayVar(&opts.HelmParams.Values.LiteralValues, "set-literal", []string{}, "Set a literal STRING value on the command line")

// upgrade only
flags.BoolVar(&opts.HelmParams.ReuseValues, "reuse-values", false, "When upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f. If '--reset-values' is specified, this is ignored")
flags.BoolVar(&opts.HelmParams.ResetValues, "reset-values", false, "When upgrading, reset the values to the ones built into the chart")

return installCmd
}
1 change: 0 additions & 1 deletion cmd/cli/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func NewMigrate() *cobra.Command {
flags.StringVar(&opts.ConfigExporter.Tag, "cfg-exporter-image-tag", DefaultImageTag, "Config Exporter job image tag")
flags.DurationVar(&opts.ConfigExporter.PollPeriod, "cfg-exporter-poll-period", 1*time.Second, "Config Exporter job poll period")
flags.DurationVar(&opts.ConfigExporter.Timeout, "cfg-exporter-timeout", 1*time.Minute, "Config Exporter job timeout")
flags.BoolVarP(&opts.Debug, "debug", "d", false, "Turn on debug logging")

return login
}
Expand Down
16 changes: 10 additions & 6 deletions cmd/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ const (
func NewRoot() *cobra.Command {
rootCmd := &cobra.Command{
Use: cli.Name,
Short: "Botkube Cloud CLI",
Short: "Botkube CLI",
Long: heredoc.WithCLIName(`
<cli> - Botkube Cloud CLI
<cli> - Botkube CLI

A utility that manages Botkube Cloud resources.
A utility that simplifies working with Botkube.

To begin working with Botkube Cloud using the <cli> CLI, start with:
Quick Start:

$ <cli> login
$ <cli> install # Install Botkube

Quick Start:
Botkube Cloud:

$ <cli> login # Login into Botkube Cloud
$ <cli> migrate # Automatically migrates Open Source installation into Botkube Cloud
`, cli.Name),
SilenceUsage: true,
Expand All @@ -37,10 +38,13 @@ func NewRoot() *cobra.Command {
},
}

cli.RegisterVerboseModeFlag(rootCmd.PersistentFlags())

rootCmd.AddCommand(
NewLogin(),
NewMigrate(),
NewDocs(),
NewInstall(),
extension.NewVersionCobraCmd(
extension.WithUpgradeNotice(orgName, repoName),
),
Expand Down
17 changes: 10 additions & 7 deletions cmd/cli/docs/botkube.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ title: botkube

## botkube

Botkube Cloud CLI
Botkube CLI

### Synopsis

botkube - Botkube Cloud CLI
botkube - Botkube CLI

A utility that manages Botkube Cloud resources.
A utility that simplifies working with Botkube.

To begin working with Botkube Cloud using the botkube CLI, start with:
Quick Start:

$ botkube login
$ botkube install # Install Botkube

Quick Start:
Botkube Cloud:

$ botkube login # Login into Botkube Cloud
$ botkube migrate # Automatically migrates Open Source installation into Botkube Cloud


Expand All @@ -28,11 +29,13 @@ botkube [flags]
### Options

```
-h, --help help for botkube
-h, --help help for botkube
-v, --verbose int/string[=simple] Prints more verbose output. Allowed values: 0 - disable, 1 - simple, 2 - trace (default 0 - disable)
```

### SEE ALSO

* [botkube install](botkube_install.md) - install Botkube into cluster
* [botkube login](botkube_login.md) - Login to a Botkube Cloud
* [botkube migrate](botkube_migrate.md) - Automatically migrates Botkube installation into Botkube Cloud
* [botkube version](botkube_version.md) - Print the CLI version
Expand Down
71 changes: 71 additions & 0 deletions cmd/cli/docs/botkube_install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: botkube install
---

## botkube install

install Botkube into cluster

### Synopsis

Use this command to install the Botkube agent.

```
botkube install [OPTIONS] [flags]
```

### Examples

```
# Install latest stable Botkube version
botkube install

# Install Botkube 0.1.0 version
botkube install --version 0.1.0

# Install Botkube from local git repository. Needs to be run from the main directory.
botkube install --repo @local
```

### Options

```
--atomic If set, process rolls back changes made in case of failed install/upgrade. The --wait flag will be set automatically if --atomic is used
--chart-name string Botkube Helm chart name. (default "botkube")
--dependency-update Update dependencies if they are missing before installing the chart
--description string add a custom description
--disable-openapi-validation If set, it will not validate rendered templates against the Kubernetes OpenAPI Schema
--dry-run Simulate an install
--force Force resource updates through a replacement strategy
-h, --help help for install
--kubeconfig string Paths to a kubeconfig. Only required if out-of-cluster.
--namespace string Botkube installation namespace. (default "botkube")
--no-hooks Disable pre/post install/upgrade hooks
--release-name string Botkube Helm chart release name. (default "botkube")
--render-subchart-notes If set, render subchart notes along with the parent
--repo string Botkube Helm chart repository location. It can be relative path to current working directory or URL. Use @stable tag to select repository which holds the stable Helm chart versions. (default "https://charts.botkube.io/")
--reset-values When upgrading, reset the values to the ones built into the chart
--reuse-values When upgrading, reuse the last release's values and merge in any overrides from the command line via --set and -f. If '--reset-values' is specified, this is ignored
--set stringArray Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--set-file stringArray Set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)
--set-json stringArray Set JSON values on the command line (can specify multiple or separate values with commas: key1=jsonval1,key2=jsonval2)
--set-literal stringArray Set a literal STRING value on the command line
--set-string stringArray Set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)
--skip-crds If set, no CRDs will be installed.
--timeout duration time to wait for any individual Kubernetes operation (like Jobs for hooks) (default 5m0s)
-f, --values strings Specify values in a YAML file or a URL (can specify multiple)
--version string Botkube version. Possible values @latest, 1.2.0, ... (default "@latest")
--wait If set, will wait until all Pods, PVCs, Services, and minimum number of Pods of a Deployment, StatefulSet, or ReplicaSet are in a ready state before marking the release as successful. It will wait for as long as --timeout (default true)
--wait-for-jobs If set and --wait enabled, will wait until all Jobs have been completed before marking the release as successful. 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

8 changes: 7 additions & 1 deletion cmd/cli/docs/botkube_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ botkube login
--local-server-addr string Address of a local server which is used for the login flow (default "localhost:8085")
```

### 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 Cloud CLI
* [botkube](botkube.md) - Botkube CLI

9 changes: 7 additions & 2 deletions cmd/cli/docs/botkube_migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ botkube migrate [OPTIONS] [flags]
--cfg-exporter-timeout duration Config Exporter job timeout (default 1m0s)
--cloud-api-url string Botkube Cloud API URL (default "https://api.botkube.io/graphql")
--cloud-dashboard-url string Botkube Cloud URL (default "https://app.botkube.io")
-d, --debug Turn on debug logging
-h, --help help for migrate
--instance-name string Botkube Cloud Instance name that will be created
-l, --label string Label of Botkube pod (default "app=botkube")
Expand All @@ -53,7 +52,13 @@ botkube migrate [OPTIONS] [flags]
--token string Botkube Cloud authentication token
```

### 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 Cloud CLI
* [botkube](botkube.md) - Botkube CLI

8 changes: 7 additions & 1 deletion cmd/cli/docs/botkube_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ botkube version -o=short
-o, --output string Output format. One of: json | pretty | short | yaml (default "pretty")
```

### 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 Cloud CLI
* [botkube](botkube.md) - Botkube CLI

Loading
Loading