mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #25876 from dshulyak/patch_change
Automatic merge from submit-queue
Use strategic patch to replace changeCause in patch command
This is partial rework of 11da9a7638
StrategicPatch will be used to update changeCause but failure wont affect command result
fixes: #24858
This commit is contained in:
commit
084b598f4d
@ -167,17 +167,18 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||||||
|
|
||||||
if !options.Local {
|
if !options.Local {
|
||||||
helper := resource.NewHelper(client, mapping)
|
helper := resource.NewHelper(client, mapping)
|
||||||
patchedObject, err := helper.Patch(namespace, name, patchType, patchBytes)
|
_, err := helper.Patch(namespace, name, patchType, patchBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if cmdutil.ShouldRecord(cmd, info) {
|
if cmdutil.ShouldRecord(cmd, info) {
|
||||||
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 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
|
||||||
// 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
|
||||||
// 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
|
||||||
// record hint is likely to be invalid anyway, so avoid the bad hint
|
patch, err := cmdutil.ChangeResourcePatch(info, f.Command())
|
||||||
resource.NewHelper(client, mapping).Replace(namespace, name, false, patchedObject)
|
if err == nil {
|
||||||
|
helper.Patch(info.Namespace, info.Name, api.StrategicMergePatchType, patch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
@ -208,7 +209,7 @@ func RunPatch(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||||||
}
|
}
|
||||||
// TODO: if we ever want to go generic, this allows a clean -o yaml without trying to print columns or anything
|
// TODO: if we ever want to go generic, this allows a clean -o yaml without trying to print columns or anything
|
||||||
// rawExtension := &runtime.Unknown{
|
// rawExtension := &runtime.Unknown{
|
||||||
// Raw: originalPatchedObjJS,
|
// Raw: originalPatchedObjJS,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
printer, err := f.PrinterForMapping(cmd, mapping, false)
|
printer, err := f.PrinterForMapping(cmd, mapping, false)
|
||||||
|
Loading…
Reference in New Issue
Block a user