Merge pull request #38112 from juanvallejo/jvallejo/add-output-format-support-kubectl-create

Automatic merge from submit-queue

Add json,yaml output format support to kubectl create, kubectl apply

Fixes: https://github.com/kubernetes/kubernetes/issues/37390

**Release note**:
```release-note
Added support for printing in all supported `--output` formats to `kubectl create ...` and `kubectl apply ...`
```

This patch adds the ability to specify an output format other than
"name" to `kubectl create ...`. It can be used in conjunction with the
`--dry-run` option. Converts unstructured objects into known types in
order to support all `--output` values.

The patch prints `*resource.Info`s returned by the server. If a resource does not yet exist (and the `--dry-run` option is not set), the resource is created and printed in the specified format.

@kubernetes/cli-review @fabianofranz
This commit is contained in:
Kubernetes Submit Queue
2017-01-03 14:18:33 -08:00
committed by GitHub
3 changed files with 33 additions and 3 deletions

View File

@@ -131,6 +131,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
}
dryRun := cmdutil.GetFlagBool(cmd, "dry-run")
output := cmdutil.GetFlagString(cmd, "output")
count := 0
err = r.Visit(func(info *resource.Info, err error) error {
@@ -154,7 +155,11 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
}
count++
shortOutput := cmdutil.GetFlagString(cmd, "output") == "name"
shortOutput := output == "name"
if len(output) > 0 && !shortOutput {
return cmdutil.PrintResourceInfoForCommand(cmd, info, f, out)
}
if !shortOutput {
f.PrintObjectSpecificMessage(info.Object, out)
}