fix --record to not fail a successful patch

This commit is contained in:
deads2k
2016-02-12 14:20:08 -05:00
parent 82c09f074b
commit 11da9a7638
2 changed files with 11 additions and 9 deletions

View File

@@ -139,18 +139,17 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
}
helper := resource.NewHelper(client, mapping)
_, err = helper.Patch(namespace, name, patchType, patchBytes)
patchedObject, err := helper.Patch(namespace, name, patchType, patchBytes)
if err != nil {
return err
}
if cmdutil.ShouldRecord(cmd, info) {
patchBytes, err = cmdutil.ChangeResourcePatch(info, f.Command())
if err != nil {
return err
}
_, err = helper.Patch(namespace, name, api.StrategicMergePatchType, patchBytes)
if err != nil {
return err
if err := cmdutil.RecordChangeCause(patchedObject, f.Command()); err == nil {
// don't return an error on failure. The patch itself succeeded, its only the hint for that change that failed
// don't bother checking for failures of this replace, because a failure to indicate the hint doesn't fail the command
// also, don't force the replacement. If the replacement fails on a resourceVersion conflict, then it means this
// record hint is likely to be invalid anyway, so avoid the bad hint
resource.NewHelper(client, mapping).Replace(namespace, name, false, patchedObject)
}
}
cmdutil.PrintSuccess(mapper, shortOutput, out, "", name, "patched")