From 8573eadb9828c03b732e5abe20b946ec1925ae87 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Tue, 9 Jun 2020 11:44:04 -0700 Subject: [PATCH] fix(cmd): display warnings on stderr The warnings introduced when a chart has been deprecated is displayed on standard out. This is a regression for users piping the output of `helm template` from a deprecated chart to `kubectl`. This changes the error message to display on standard error instead. Signed-off-by: Matthew Fisher --- cmd/helm/helm.go | 5 +++++ cmd/helm/install.go | 3 +-- cmd/helm/testdata/output/deprecated-chart.txt | 1 - cmd/helm/upgrade.go | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 4463cebd9..e7328d16f 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -56,6 +56,11 @@ func debug(format string, v ...interface{}) { } } +func warning(format string, v ...interface{}) { + format = fmt.Sprintf("WARNING: %s\n", format) + fmt.Fprintf(os.Stderr, format, v...) +} + func initKubeLogs() { pflag.CommandLine.SetNormalizeFunc(wordSepNormalizeFunc) gofs := flag.NewFlagSet("klog", flag.ExitOnError) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 164462850..ae750e45c 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "fmt" "io" <<<<<<< HEAD "io/ioutil" @@ -213,7 +212,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options } if chartRequested.Metadata.Deprecated { - fmt.Fprintln(out, "WARNING: This chart is deprecated") + warning("This chart is deprecated") } if req := chartRequested.Metadata.Dependencies; req != nil { diff --git a/cmd/helm/testdata/output/deprecated-chart.txt b/cmd/helm/testdata/output/deprecated-chart.txt index e5be2c3f1..039d6aef6 100644 --- a/cmd/helm/testdata/output/deprecated-chart.txt +++ b/cmd/helm/testdata/output/deprecated-chart.txt @@ -1,4 +1,3 @@ -WARNING: This chart is deprecated NAME: aeneas LAST DEPLOYED: Fri Sep 2 22:04:05 1977 NAMESPACE: default diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index d8753f0e0..12b7bec80 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -149,7 +149,7 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if ch.Metadata.Deprecated { - fmt.Fprintln(out, "WARNING: This chart is deprecated") + warning("This chart is deprecated") } err = loadExternalFiles(ch, client.ExternalFiles)