From 5140b246acc654f1bb3f64a56c69edd5f20bf845 Mon Sep 17 00:00:00 2001 From: divolgin Date: Thu, 1 Dec 2022 17:16:04 -0800 Subject: [PATCH] Use stdout in registry writer only with commands that don't use structured output Signed-off-by: divolgin --- cmd/helm/get_values.go | 2 ++ cmd/helm/history.go | 2 ++ cmd/helm/install.go | 2 ++ cmd/helm/list.go | 2 ++ cmd/helm/root.go | 10 +++++++++- cmd/helm/status.go | 1 + cmd/helm/template.go | 3 +++ cmd/helm/upgrade.go | 2 ++ 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/helm/get_values.go b/cmd/helm/get_values.go index 6124e1b33..83747eebc 100644 --- a/cmd/helm/get_values.go +++ b/cmd/helm/get_values.go @@ -53,6 +53,8 @@ func newGetValuesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return compListReleases(toComplete, args, cfg) }, RunE: func(cmd *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) + vals, err := client.Run(args[0]) if err != nil { return err diff --git a/cmd/helm/history.go b/cmd/helm/history.go index ee6f391e4..645a1f8df 100644 --- a/cmd/helm/history.go +++ b/cmd/helm/history.go @@ -67,6 +67,8 @@ func newHistoryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return compListReleases(toComplete, args, cfg) }, RunE: func(cmd *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) + history, err := getHistory(client, args[0]) if err != nil { return err diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 281679e5c..155753cc9 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -136,6 +136,8 @@ func newInstallCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return compInstall(args, toComplete, client) }, RunE: func(_ *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) + rel, err := runInstall(args, client, valueOpts, out) if err != nil { return errors.Wrap(err, "INSTALLATION FAILED") diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 5ca3de18e..c7dffd6f3 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -70,6 +70,8 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { Args: require.NoArgs, ValidArgsFunction: noCompletions, RunE: func(cmd *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) + if client.AllNamespaces { if err := cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug); err != nil { return err diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 7da57c6aa..8298296e5 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -30,6 +30,7 @@ import ( "k8s.io/client-go/tools/clientcmd" "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/cli/output" "helm.sh/helm/v3/pkg/registry" "helm.sh/helm/v3/pkg/repo" ) @@ -155,7 +156,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string registryClient, err := registry.NewClient( registry.ClientOptDebug(settings.Debug), registry.ClientOptEnableCache(true), - registry.ClientOptWriter(os.Stderr), + registry.ClientOptWriter(out), registry.ClientOptCredentialsFile(settings.RegistryConfig), ) if err != nil { @@ -261,3 +262,10 @@ func checkForExpiredRepos(repofile string) { } } + +func overrideRegistryWriter(cfg *action.Configuration, outfmt output.Format) { + // Ensure registry output doesn't break structured output + if outfmt != output.Table { + registry.ClientOptWriter(os.Stderr)(cfg.RegistryClient) + } +} diff --git a/cmd/helm/status.go b/cmd/helm/status.go index aa22aa02a..a3690c69b 100644 --- a/cmd/helm/status.go +++ b/cmd/helm/status.go @@ -65,6 +65,7 @@ func newStatusCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return compListReleases(toComplete, args, cfg) }, RunE: func(cmd *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) // When the output format is a table the resources should be fetched // and displayed as a table. When YAML or JSON the resources will be diff --git a/cmd/helm/template.go b/cmd/helm/template.go index ce2be55bc..28444335c 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -34,6 +34,7 @@ import ( "helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chartutil" + "helm.sh/helm/v3/pkg/cli/output" "helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/releaseutil" ) @@ -65,6 +66,8 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return compInstall(args, toComplete, client) }, RunE: func(_ *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, output.YAML) + if kubeVersion != "" { parsedKubeVersion, err := chartutil.ParseKubeVersion(kubeVersion) if err != nil { diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 02f4cf2a9..9ff74a0b1 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -88,6 +88,8 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return nil, cobra.ShellCompDirectiveNoFileComp }, RunE: func(cmd *cobra.Command, args []string) error { + overrideRegistryWriter(cfg, outfmt) + client.Namespace = settings.Namespace() // Fixes #7002 - Support reading values from STDIN for `upgrade` command