mirror of https://github.com/k3s-io/k3s
Merge pull request #67399 from deads2k/cli-04-patch
Automatic merge from submit-queue (batch tested with PRs 67399, 67471, 66815, 67301, 55840). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. update patch to work with --local and avoid extra requests --local wasn't being respected by the resourcebuilder and then the later refreshes were unnecessary and violated --local in some cases. @kubernetes/sig-cli-maintainers @juanvallejo ```release-note kubectl patch now respects --local ```pull/8/head
commit
4ccee77fad
|
@ -193,6 +193,7 @@ func (o *PatchOptions) RunPatch() error {
|
|||
r := o.builder.
|
||||
Unstructured().
|
||||
ContinueOnError().
|
||||
LocalParam(o.Local).
|
||||
NamespaceParam(o.namespace).DefaultNamespace().
|
||||
FilenameParam(o.enforceNamespace, &o.FilenameOptions).
|
||||
ResourceTypeOrNameArgs(false, o.args...).
|
||||
|
@ -208,14 +209,16 @@ func (o *PatchOptions) RunPatch() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
count++
|
||||
name, namespace := info.Name, info.Namespace
|
||||
mapping := info.ResourceMapping()
|
||||
client, err := o.unstructuredClientForMapping(mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !o.Local && !o.dryRun {
|
||||
mapping := info.ResourceMapping()
|
||||
client, err := o.unstructuredClientForMapping(mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
helper := resource.NewHelper(client, mapping)
|
||||
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes)
|
||||
if err != nil {
|
||||
|
@ -234,29 +237,20 @@ func (o *PatchOptions) RunPatch() error {
|
|||
patchedObj = recordedObj
|
||||
}
|
||||
}
|
||||
count++
|
||||
|
||||
// After computing whether we changed data, refresh the resource info with the resulting object
|
||||
if err := info.Refresh(patchedObj, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter(patchOperation(didPatch))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
return printer.PrintObj(patchedObj, o.Out)
|
||||
}
|
||||
|
||||
count++
|
||||
|
||||
originalObjJS, err := runtime.Encode(unstructured.UnstructuredJSONScheme, info.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
originalPatchedObjJS, err := getPatchedJSON(patchType, originalObjJS, patchBytes, mapping.GroupVersionKind, scheme.Scheme)
|
||||
originalPatchedObjJS, err := getPatchedJSON(patchType, originalObjJS, patchBytes, info.Object.GetObjectKind().GroupVersionKind(), scheme.Scheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -267,22 +261,11 @@ func (o *PatchOptions) RunPatch() error {
|
|||
}
|
||||
|
||||
didPatch := !reflect.DeepEqual(info.Object, targetObj)
|
||||
|
||||
// TODO: if we ever want to go generic, this allows a clean -o yaml without trying to print columns or anything
|
||||
// rawExtension := &runtime.Unknown{
|
||||
// Raw: originalPatchedObjJS,
|
||||
// }
|
||||
if didPatch {
|
||||
if err := info.Refresh(targetObj, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
printer, err := o.ToPrinter(patchOperation(didPatch))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return printer.PrintObj(info.Object, o.Out)
|
||||
return printer.PrintObj(targetObj, o.Out)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue