From cade00e6460fdf5baea6c382e8796d282897205e Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Tue, 20 Dec 2016 15:35:28 -0500 Subject: [PATCH 1/3] do not filter kubectl get pods if -o json or yaml This patch sets the value of --show-all to true if the output format specified is 'json' or 'yaml'. --- pkg/kubectl/cmd/get.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 9ddb225e209..c389bc61ba9 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -187,8 +187,11 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ if err != nil { return err } - if len(options.Filenames) > 0 || argsHasNames { - cmd.Flag("show-all").Value.Set("true") + output := cmdutil.GetFlagString(cmd, "output") + if len(options.Filenames) > 0 || argsHasNames || output == "json" || output == "yaml" { + if !cmd.Flag("show-all").Changed { + cmd.Flag("show-all").Value.Set("true") + } } export := cmdutil.GetFlagBool(cmd, "export") From 430283b973c5420429fccc2368240534055402c6 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Mon, 16 Jan 2017 13:58:55 -0500 Subject: [PATCH 2/3] add OutputsRawFormat helper; default show-all on multiple resource kinds --- pkg/kubectl/cmd/get.go | 7 ++++--- pkg/kubectl/cmd/util/helpers.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index c389bc61ba9..d16f72563c8 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -182,13 +182,14 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ return cmdutil.UsageError(cmd, usageString) } - // always show resources when getting by name or filename argsHasNames, err := resource.HasNames(args) if err != nil { return err } - output := cmdutil.GetFlagString(cmd, "output") - if len(options.Filenames) > 0 || argsHasNames || output == "json" || output == "yaml" { + + // always show resources when getting by name or filename, or if the output + // is machine-consumable, or if multiple resource kinds were requested. + if len(options.Filenames) > 0 || argsHasNames || cmdutil.OutputsRawFormat(cmd) || resource.MultipleTypesRequested(args) { if !cmd.Flag("show-all").Changed { cmd.Flag("show-all").Value.Set("true") } diff --git a/pkg/kubectl/cmd/util/helpers.go b/pkg/kubectl/cmd/util/helpers.go index ab4bb4699ad..5c95739a282 100644 --- a/pkg/kubectl/cmd/util/helpers.go +++ b/pkg/kubectl/cmd/util/helpers.go @@ -729,3 +729,19 @@ func RequireNoArguments(c *cobra.Command, args []string) { CheckErr(UsageError(c, fmt.Sprintf(`unknown command %q`, strings.Join(args, " ")))) } } + +// OutputsRawFormat determines if a command's output format is machine parsable +// or returns false if it is human readable (name, wide, etc.) +func OutputsRawFormat(cmd *cobra.Command) bool { + output := GetFlagString(cmd, "output") + if output == "json" || + output == "yaml" || + output == "go-template" || + output == "go-template-file" || + output == "jsonpath" || + output == "jsonpath-file" { + return true + } + + return false +} From 713df3d74ea470a927a106f630cefbdc1de1e406 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Wed, 18 Jan 2017 13:26:03 -0500 Subject: [PATCH 3/3] remove check for multiple resource types --- pkg/kubectl/cmd/get.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index d16f72563c8..d526c598fdc 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -189,7 +189,7 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [ // always show resources when getting by name or filename, or if the output // is machine-consumable, or if multiple resource kinds were requested. - if len(options.Filenames) > 0 || argsHasNames || cmdutil.OutputsRawFormat(cmd) || resource.MultipleTypesRequested(args) { + if len(options.Filenames) > 0 || argsHasNames || cmdutil.OutputsRawFormat(cmd) { if !cmd.Flag("show-all").Changed { cmd.Flag("show-all").Value.Set("true") }