Skip to content

Commit

Permalink
Apply fixes, add scrolling logs printing
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Jul 13, 2023
1 parent 9b4031c commit 7a8b838
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 305 deletions.
5 changes: 1 addition & 4 deletions cmd/botkube-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -67,9 +66,7 @@ func main() {
ctx, cancelCtxFn := context.WithCancel(ctx)
defer cancelCtxFn()

if err := run(ctx); err != nil {
log.Fatal(err)
}
loggerx.ExitOnError(run(ctx), "while running application")
}

// run wraps the main logic of the app to be able to properly clean up resources via deferred calls.
Expand Down
5 changes: 2 additions & 3 deletions cmd/cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func NewInstall() *cobra.Command {
kubex.RegisterKubeconfigFlag(flags)
flags.BoolVar(&opts.LogsReportTimestamp, "logs-report-timestamp", false, "Print timestamp prefix to the Botkube logs entries")
flags.IntVar(&opts.LogsScrollingHeight, "logs-scrolling-height", 10, "")
flags.DurationVar(&opts.Timeout, "timeout", 10*time.Minute, `Maximum time during which the Botkube installation is being watched, where "0" means "infinite". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".`)
flags.BoolVarP(&opts.Watch, "watch", "w", true, "Watches the status of the Botkube installation until it finish or the defined `--timeout` occurs.")

// common params for install and upgrade operation
flags.StringVar(&opts.HelmParams.Version, "version", install.LatestVersionTag, "Botkube version. Possible values @latest, 1.2.0, ...")
Expand All @@ -61,9 +63,6 @@ func NewInstall() *cobra.Command {
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", false, "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")
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/install/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package install

import (
"time"

"github.com/kubeshop/botkube/internal/cli/install/helm"
)

Expand All @@ -27,4 +29,6 @@ type Config struct {
HelmParams helm.Config
LogsReportTimestamp bool
LogsScrollingHeight int
Watch bool
Timeout time.Duration
}
5 changes: 0 additions & 5 deletions internal/cli/install/helm/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package helm

import (
"time"

"helm.sh/helm/v3/pkg/cli/values"
)

Expand All @@ -20,9 +18,6 @@ type Config struct {

Namespace string
SkipCRDs bool
Timeout time.Duration
Wait bool
WaitForJobs bool
DisableHooks bool
DryRun bool
Force bool
Expand Down
20 changes: 11 additions & 9 deletions internal/cli/install/helm/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ func NewHelm(k8sCfg *rest.Config, forNamespace string) (*Helm, error) {
// Install installs a given Helm chart.
func (c *Helm) Install(ctx context.Context, status *printer.StatusPrinter, opts Config) (*release.Release, error) {
histClient := action.NewHistory(c.helmCfg)
histClient.Max = 1
_, err := histClient.Run(opts.ReleaseName)
//histClient.Max = 1
rels, err := histClient.Run(opts.ReleaseName)
var runFn Run
switch {
case err == nil:
if err := PrintReleaseStatus("Detected existing Botkube installation:", status, rels[len(rels)-1]); err != nil {
return nil, err
}

prompt := &survey.Confirm{
Message: "Detected existing Botkube installation. Do you want to upgrade it?",
Message: "Do you want to upgrade existing installation?",
Default: true,
}

Expand Down Expand Up @@ -133,9 +137,8 @@ func (c *Helm) installAction(opts Config) Run {

installCli.Namespace = opts.Namespace
installCli.SkipCRDs = opts.SkipCRDs
installCli.Timeout = opts.Timeout
//installCli.Wait = opts.Wait
installCli.WaitForJobs = opts.WaitForJobs
installCli.Wait = false // botkube CLI has a custom logic to do that
installCli.WaitForJobs = false
installCli.DisableHooks = opts.DisableHooks
installCli.DryRun = opts.DryRun
installCli.Force = opts.Force
Expand All @@ -157,9 +160,8 @@ func (c *Helm) upgradeAction(opts Config) Run {

upgradeAction.Namespace = opts.Namespace
upgradeAction.SkipCRDs = opts.SkipCRDs
upgradeAction.Timeout = opts.Timeout
//upgradeAction.Wait = opts.Wait
upgradeAction.WaitForJobs = opts.WaitForJobs
upgradeAction.Wait = false // botkube CLI has a custom logic to do that
upgradeAction.WaitForJobs = false
upgradeAction.DisableHooks = opts.DisableHooks
upgradeAction.DryRun = opts.DryRun
upgradeAction.Force = opts.Force
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/install/helm/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
var releaseGoTpl = `
{{ Key "Name" }} {{ .Name | Val }}
{{ Key "Namespace" }} {{ .Namespace | Val }}
{{ Key "Version" }} {{ .Version | Val }}
{{ Key "Last Deployed" }} {{ .LastDeployed | FmtDate | Val }}
{{ Key "Revision" }} {{ .Revision | Val }}
{{ Key "Description" }} {{ .Description | Val }}
`

// PrintReleaseStatus returns release description similar to what Helm does,
// based on https://github.com/helm/helm/blob/f31d4fb3aacabf6102b3ec9214b3433a3dbf1812/cmd/helm/status.go#L126C1-L138C3
func PrintReleaseStatus(status *printer.StatusPrinter, r *release.Release) error {
func PrintReleaseStatus(header string, status *printer.StatusPrinter, r *release.Release) error {
if r == nil {
return nil
}
Expand All @@ -35,6 +35,7 @@ func PrintReleaseStatus(status *printer.StatusPrinter, r *release.Release) error
}
properties["Namespace"] = r.Namespace
properties["Status"] = r.Info.Status.String()
properties["Version"] = r.Chart.AppVersion()
properties["Revision"] = fmt.Sprintf("%d", r.Version)
properties["Description"] = r.Info.Description

Expand All @@ -43,6 +44,6 @@ func PrintReleaseStatus(status *printer.StatusPrinter, r *release.Release) error
return err
}

status.InfoWithBody("Release details:", indent.String(desc, 2))
status.InfoWithBody(header, indent.String(desc, 2))
return nil
}
131 changes: 0 additions & 131 deletions internal/cli/install/helm/wait.go

This file was deleted.

Loading

0 comments on commit 7a8b838

Please sign in to comment.