ref(helm): use new debug method to standardize debug output

pull/2304/head
Adam Reese 8 years ago
parent 5af676cda1
commit 50eee83646
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -100,7 +100,7 @@ func (d *dependencyUpdateCmd) run() error {
if d.verify { if d.verify {
man.Verify = downloader.VerifyIfPossible man.Verify = downloader.VerifyIfPossible
} }
if settings.FlagDebug { if settings.Debug {
man.Debug = true man.Debug = true
} }
return man.Update() return man.Update()

@ -105,7 +105,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
settings.Home = helmpath.Home(helmHomeTemp) settings.Home = helmpath.Home(helmHomeTemp)
p.StringVar(&settings.TillerHost, "host", helm_env.DefaultHelmHost(), "address of tiller. Overrides $HELM_HOST") p.StringVar(&settings.TillerHost, "host", helm_env.DefaultHelmHost(), "address of tiller. Overrides $HELM_HOST")
p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use") p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVar(&settings.FlagDebug, "debug", false, "enable verbose output") p.BoolVar(&settings.Debug, "debug", false, "enable verbose output")
p.StringVar(&settings.TillerNamespace, "tiller-namespace", tiller_env.GetTillerNamespace(), "namespace of tiller") p.StringVar(&settings.TillerNamespace, "tiller-namespace", tiller_env.GetTillerNamespace(), "namespace of tiller")
if os.Getenv(helm_env.PluginDisableEnvVar) != "1" { if os.Getenv(helm_env.PluginDisableEnvVar) != "1" {
@ -190,15 +190,12 @@ func setupConnection(c *cobra.Command, args []string) error {
} }
settings.TillerHost = fmt.Sprintf("localhost:%d", tunnel.Local) settings.TillerHost = fmt.Sprintf("localhost:%d", tunnel.Local)
if settings.FlagDebug { debug("Created tunnel using local port: '%d'\n", tunnel.Local)
fmt.Printf("Created tunnel using local port: '%d'\n", tunnel.Local)
}
} }
// Set up the gRPC config. // Set up the gRPC config.
if settings.FlagDebug { debug("SERVER: %q\n", settings.TillerHost)
fmt.Printf("SERVER: %q\n", settings.TillerHost)
}
// Plugin support. // Plugin support.
return nil return nil
} }

@ -36,7 +36,7 @@ func newHomeCmd(out io.Writer) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
h := settings.Home h := settings.Home
fmt.Fprintf(out, "%s\n", h) fmt.Fprintf(out, "%s\n", h)
if settings.FlagDebug { if settings.Debug {
fmt.Fprintf(out, "Repository: %s\n", h.Repository()) fmt.Fprintf(out, "Repository: %s\n", h.Repository())
fmt.Fprintf(out, "RepositoryFile: %s\n", h.RepositoryFile()) fmt.Fprintf(out, "RepositoryFile: %s\n", h.RepositoryFile())
fmt.Fprintf(out, "Cache: %s\n", h.Cache()) fmt.Fprintf(out, "Cache: %s\n", h.Cache())

@ -155,7 +155,7 @@ func (i *initCmd) run() error {
i.opts.UseCanary = i.canary i.opts.UseCanary = i.canary
i.opts.ImageSpec = i.image i.opts.ImageSpec = i.image
if settings.FlagDebug { if settings.Debug {
writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error { writeYAMLManifest := func(apiVersion, kind, body string, first, last bool) error {
w := i.out w := i.out
if !first { if !first {

@ -140,11 +140,11 @@ func TestInitCmd_dryRun(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
dbg := settings.FlagDebug dbg := settings.Debug
settings.FlagDebug = true settings.Debug = true
defer func() { defer func() {
os.Remove(home) os.Remove(home)
settings.FlagDebug = dbg settings.Debug = dbg
}() }()
var buf bytes.Buffer var buf bytes.Buffer

@ -178,9 +178,7 @@ func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
} }
func (i *installCmd) run() error { func (i *installCmd) run() error {
if settings.FlagDebug { debug("CHART PATH: %s\n", i.chartPath)
fmt.Fprintf(i.out, "CHART PATH: %s\n", i.chartPath)
}
if i.namespace == "" { if i.namespace == "" {
i.namespace = defaultNamespace() i.namespace = defaultNamespace()
@ -305,14 +303,14 @@ func (i *installCmd) vals() ([]byte, error) {
return yaml.Marshal(base) return yaml.Marshal(base)
} }
// printRelease prints info about a release if the flagDebug is true. // printRelease prints info about a release if the Debug is true.
func (i *installCmd) printRelease(rel *release.Release) { func (i *installCmd) printRelease(rel *release.Release) {
if rel == nil { if rel == nil {
return return
} }
// TODO: Switch to text/template like everything else. // TODO: Switch to text/template like everything else.
fmt.Fprintf(i.out, "NAME: %s\n", rel.Name) fmt.Fprintf(i.out, "NAME: %s\n", rel.Name)
if settings.FlagDebug { if settings.Debug {
printRelease(i.out, rel) printRelease(i.out, rel)
} }
} }
@ -371,11 +369,9 @@ func locateChartPath(name, version string, verify bool, keyring string) (string,
if err != nil { if err != nil {
return filename, err return filename, err
} }
if settings.FlagDebug { debug("Fetched %s to %s\n", name, filename)
fmt.Printf("Fetched %s to %s\n", name, filename)
}
return lname, nil return lname, nil
} else if settings.FlagDebug { } else if settings.Debug {
return filename, err return filename, err
} }

@ -119,9 +119,7 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error {
if err := setVersion(ch, p.version); err != nil { if err := setVersion(ch, p.version); err != nil {
return err return err
} }
if settings.FlagDebug { debug("Setting version to %s", p.version)
fmt.Fprintf(p.out, "Setting version to %s", p.version)
}
} }
if filepath.Base(path) != ch.Metadata.Name { if filepath.Base(path) != ch.Metadata.Name {
@ -145,8 +143,8 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error {
} }
name, err := chartutil.Save(ch, dest) name, err := chartutil.Save(ch, dest)
if err == nil && settings.FlagDebug { if err == nil {
fmt.Fprintf(p.out, "Saved %s to current directory\n", name) debug("Saved %s to current directory\n", name)
} }
// Save to $HELM_HOME/local directory. This is second, because we don't want // Save to $HELM_HOME/local directory. This is second, because we don't want
@ -155,9 +153,8 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error {
lr := p.home.LocalRepository() lr := p.home.LocalRepository()
if err := repo.AddChartToLocalRepo(ch, lr); err != nil { if err := repo.AddChartToLocalRepo(ch, lr); err != nil {
return err return err
} else if settings.FlagDebug {
fmt.Fprintf(p.out, "Saved %s to %s\n", name, lr)
} }
debug("Saved %s to %s\n", name, lr)
} }
if p.sign { if p.sign {
@ -194,9 +191,7 @@ func (p *packageCmd) clearsign(filename string) error {
return err return err
} }
if settings.FlagDebug { debug(sig)
fmt.Fprintln(p.out, sig)
}
return ioutil.WriteFile(filename+".prov", []byte(sig), 0755) return ioutil.WriteFile(filename+".prov", []byte(sig), 0755)
} }

@ -59,7 +59,7 @@ func (pcmd *pluginInstallCmd) complete(args []string) error {
} }
func (pcmd *pluginInstallCmd) run() error { func (pcmd *pluginInstallCmd) run() error {
installer.Debug = settings.FlagDebug installer.Debug = settings.Debug
i, err := installer.NewForSource(pcmd.source, pcmd.version, pcmd.home) i, err := installer.NewForSource(pcmd.source, pcmd.version, pcmd.home)
if err != nil { if err != nil {

@ -162,9 +162,9 @@ func TestSetupEnv(t *testing.T) {
settings.Home = helmpath.Home("testdata/helmhome") settings.Home = helmpath.Home("testdata/helmhome")
base := filepath.Join(settings.Home.Plugins(), name) base := filepath.Join(settings.Home.Plugins(), name)
settings.PlugDirs = settings.Home.Plugins() settings.PlugDirs = settings.Home.Plugins()
settings.FlagDebug = true settings.Debug = true
defer func() { defer func() {
settings.FlagDebug = false settings.Debug = false
}() }()
plugin.SetupPluginEnv(settings, name, base) plugin.SetupPluginEnv(settings, name, base)

@ -75,7 +75,7 @@ func tpl(t string, vals map[string]interface{}, out io.Writer) error {
} }
func debug(format string, args ...interface{}) { func debug(format string, args ...interface{}) {
if settings.FlagDebug { if settings.Debug {
format = fmt.Sprintf("[debug] %s\n", format) format = fmt.Sprintf("[debug] %s\n", format)
fmt.Printf(format, args...) fmt.Printf(format, args...)
} }

@ -185,7 +185,7 @@ func (u *upgradeCmd) run() error {
return fmt.Errorf("UPGRADE FAILED: %v", prettyError(err)) return fmt.Errorf("UPGRADE FAILED: %v", prettyError(err))
} }
if settings.FlagDebug { if settings.Debug {
printRelease(u.out, resp.Release) printRelease(u.out, resp.Release)
} }

@ -20,7 +20,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -105,9 +104,7 @@ func (v *versionCmd) run() error {
if grpc.Code(err) == codes.Unimplemented { if grpc.Code(err) == codes.Unimplemented {
return errors.New("server is too old to know its version") return errors.New("server is too old to know its version")
} }
if settings.FlagDebug { debug("%s", err)
fmt.Fprintln(os.Stderr, err)
}
return errors.New("cannot connect to Tiller") return errors.New("cannot connect to Tiller")
} }
fmt.Fprintf(v.out, "Server: %s\n", formatVersion(resp.Version, v.short)) fmt.Fprintf(v.out, "Server: %s\n", formatVersion(resp.Version, v.short))

@ -52,5 +52,5 @@ type EnvSettings struct {
TillerNamespace string TillerNamespace string
Home helmpath.Home Home helmpath.Home
PlugDirs string PlugDirs string
FlagDebug bool Debug bool
} }

@ -195,7 +195,7 @@ func SetupPluginEnv(settings helm_env.EnvSettings,
os.Setenv(key, val) os.Setenv(key, val)
} }
if settings.FlagDebug { if settings.Debug {
os.Setenv("HELM_DEBUG", "1") os.Setenv("HELM_DEBUG", "1")
} }
} }

Loading…
Cancel
Save