mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
update patch to work with --local and avoid extra requests
This commit is contained in:
parent
d0439d417b
commit
562209d632
@ -193,6 +193,7 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
r := o.builder.
|
r := o.builder.
|
||||||
Unstructured().
|
Unstructured().
|
||||||
ContinueOnError().
|
ContinueOnError().
|
||||||
|
LocalParam(o.Local).
|
||||||
NamespaceParam(o.namespace).DefaultNamespace().
|
NamespaceParam(o.namespace).DefaultNamespace().
|
||||||
FilenameParam(o.enforceNamespace, &o.FilenameOptions).
|
FilenameParam(o.enforceNamespace, &o.FilenameOptions).
|
||||||
ResourceTypeOrNameArgs(false, o.args...).
|
ResourceTypeOrNameArgs(false, o.args...).
|
||||||
@ -208,14 +209,16 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
count++
|
||||||
name, namespace := info.Name, info.Namespace
|
name, namespace := info.Name, info.Namespace
|
||||||
mapping := info.ResourceMapping()
|
|
||||||
client, err := o.unstructuredClientForMapping(mapping)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !o.Local && !o.dryRun {
|
if !o.Local && !o.dryRun {
|
||||||
|
mapping := info.ResourceMapping()
|
||||||
|
client, err := o.unstructuredClientForMapping(mapping)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
helper := resource.NewHelper(client, mapping)
|
helper := resource.NewHelper(client, mapping)
|
||||||
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes)
|
patchedObj, err := helper.Patch(namespace, name, patchType, patchBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -234,29 +237,20 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
patchedObj = recordedObj
|
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))
|
printer, err := o.ToPrinter(patchOperation(didPatch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return printer.PrintObj(patchedObj, o.Out)
|
||||||
return printer.PrintObj(info.Object, o.Out)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
count++
|
|
||||||
|
|
||||||
originalObjJS, err := runtime.Encode(unstructured.UnstructuredJSONScheme, info.Object)
|
originalObjJS, err := runtime.Encode(unstructured.UnstructuredJSONScheme, info.Object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -267,22 +261,11 @@ func (o *PatchOptions) RunPatch() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
didPatch := !reflect.DeepEqual(info.Object, targetObj)
|
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))
|
printer, err := o.ToPrinter(patchOperation(didPatch))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return printer.PrintObj(info.Object, o.Out)
|
return printer.PrintObj(targetObj, o.Out)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user