Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add --quiet to install
Browse files Browse the repository at this point in the history
This will suppress all installation output except for errors
encountered. The motivation is to use this flag when manager installs
acorn because these interactive terminal messages aren't useful in that
scenario.

Signed-off-by: Craig Jellick <[email protected]>
  • Loading branch information
cjellick committed Aug 30, 2023
1 parent f77a2dd commit 0cd578e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/docs/100-reference/01-command-line/acorn_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ acorn install
--propagate-project-annotation strings The list of keys of annotations to propagate from acorn project to app namespaces
--propagate-project-label strings The list of keys of labels to propagate from acorn project to app namespaces
--publish-builders Publish the builders through ingress to so build traffic does not traverse the api-server
--quiet Only output errors encountered during installation
--record-builds Keep a record of each acorn build that happens
--registry-cpu string The CPU to allocate to the registry in the format of <req>:<limit> (example 200m:1000m)
--registry-memory string The memory to allocate to the registry in the format of <req>:<limit> (example 256Mi:1Gi)
Expand Down
9 changes: 5 additions & 4 deletions pkg/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ acorn install`,
}

type Install struct {
SkipChecks bool `usage:"Bypass installation checks"`

Image string `usage:"Override the default image used for the deployment"`
Output string `usage:"Output manifests instead of applying them (json, yaml)" short:"o"`
SkipChecks bool `usage:"Bypass installation checks"`
Quiet bool `usage:"Only output errors encountered during installation"`
Image string `usage:"Override the default image used for the deployment"`
Output string `usage:"Output manifests instead of applying them (json, yaml)" short:"o"`

APIServerReplicas *int `usage:"acorn-api deployment replica count" name:"api-server-replicas"`
APIServerPodAnnotations []string `usage:"annotations to apply to acorn-api pods" name:"api-server-pod-annotations" split:"false"`
Expand Down Expand Up @@ -96,6 +96,7 @@ func (i *Install) Run(cmd *cobra.Command, args []string) error {

opts := &install.Options{
SkipChecks: i.SkipChecks,
Quiet: i.Quiet,
OutputFormat: i.Output,
Config: i.Config,
APIServerReplicas: i.APIServerReplicas,
Expand Down
11 changes: 9 additions & 2 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Options struct {
ControllerServiceAccountAnnotations map[string]string
Config apiv1.Config
Progress progress.Builder
Quiet bool
}

func (o *Options) complete() *Options {
Expand All @@ -75,7 +76,11 @@ func (o *Options) complete() *Options {
}

if o.Progress == nil {
o.Progress = &term.Builder{}
if o.Quiet {
o.Progress = &term.QuietBuilder{}
} else {
o.Progress = &term.Builder{}
}
}

if o.APIServerReplicas == nil {
Expand Down Expand Up @@ -293,7 +298,9 @@ func Install(ctx context.Context, image string, opts *Options) error {
}
}

pterm.Success.Println("Installation done")
if !opts.Quiet {
pterm.Success.Println("Installation done")
}
return nil
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/term/quiet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package term

import (
"github.com/acorn-io/runtime/pkg/install/progress"
"github.com/sirupsen/logrus"
)

type QuietBuilder struct {
}

func (b *QuietBuilder) New(msg string) progress.Progress {
return newQuietSpinner(msg)
}

type quietSpinner struct {
text string
}

func newQuietSpinner(text string) *quietSpinner {
return &quietSpinner{
text: text,
}
}

func (s *quietSpinner) Fail(err error) error {
if err != nil {
logrus.Errorf("Error encountered during '%v': %v", s.text, err)
}
return err
}

func (*quietSpinner) Infof(string, ...any) {
// No-op, we're being quiet
}

func (*quietSpinner) SuccessWithWarning(string, ...any) {
// No-op, we're being quiet
}

func (*quietSpinner) Success() {
// No-op, we're being quiet
}

0 comments on commit 0cd578e

Please sign in to comment.