mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-31 16:46:54 +00:00
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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user