Honor output formats in kubectl patch

This commit is contained in:
Jordan Liggitt
2017-02-20 21:12:13 -05:00
parent 7f626cf836
commit 56d141851f
2 changed files with 66 additions and 17 deletions

View File

@@ -191,13 +191,19 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
infoCopy.Object = patchedObj
infoCopy.VersionedObject = patchedObj
if patch, patchType, err := cmdutil.ChangeResourcePatch(&infoCopy, f.Command(cmd, true)); err == nil {
if _, err = helper.Patch(info.Namespace, info.Name, patchType, patch); err != nil {
if recordedObj, err := helper.Patch(info.Namespace, info.Name, patchType, patch); err != nil {
glog.V(4).Infof("error recording reason: %v", err)
} else {
patchedObj = recordedObj
}
}
}
count++
if err := info.Refresh(patchedObj, true); err != nil {
return err
}
oldData, err := json.Marshal(info.Object)
if err != nil {
return err
@@ -210,9 +216,10 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
dataChangedMsg = "patched"
}
if options.OutputFormat == "name" || len(options.OutputFormat) == 0 {
cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
if len(options.OutputFormat) > 0 && options.OutputFormat != "name" {
return cmdutil.PrintResourceInfoForCommand(cmd, info, f, out)
}
cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
return nil
}
@@ -234,16 +241,10 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
// rawExtension := &runtime.Unknown{
// Raw: originalPatchedObjJS,
// }
printer, err := f.PrinterForMapping(cmd, mapping, false)
if err != nil {
if err := info.Refresh(targetObj, true); err != nil {
return err
}
if err := printer.PrintObj(targetObj, out); err != nil {
return err
}
return nil
return cmdutil.PrintResourceInfoForCommand(cmd, info, f, out)
})
if err != nil {
return err