Commit 4520819d authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #39042 from juanvallejo/jvallejo/dont-filter-pods-if-json-or-yaml

Automatic merge from submit-queue (batch tested with PRs 36467, 36528, 39568, 40094, 39042) do not filter kubectl get pods if -o json or yaml Fixes: https://github.com/kubernetes/kubernetes/issues/38327 This patch sets the value of --show-all to true if the output format specified is 'json' or 'yaml'. **Release note**: ```release-note release-note-none ``` @smarterclayton
parents 76d023ca 713df3d7
......@@ -183,13 +183,17 @@ 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
}
if len(options.Filenames) > 0 || argsHasNames {
cmd.Flag("show-all").Value.Set("true")
// 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) {
if !cmd.Flag("show-all").Changed {
cmd.Flag("show-all").Value.Set("true")
}
}
export := cmdutil.GetFlagBool(cmd, "export")
......
......@@ -733,3 +733,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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment