From 5fd1ca268763d7c9b53206d02a0916835c4a68ad Mon Sep 17 00:00:00 2001 From: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:51:54 +0530 Subject: [PATCH] Do not deep copy source resources while rebasing Only copy them when required Signed-off-by: Praveen Rewar <8457124+praveenrewar@users.noreply.github.com> --- pkg/kapp/diff/rebased_resource.go | 6 +++--- pkg/kapp/resources/mod_field_copy.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/kapp/diff/rebased_resource.go b/pkg/kapp/diff/rebased_resource.go index 1ad53d027..1130d3745 100644 --- a/pkg/kapp/diff/rebased_resource.go +++ b/pkg/kapp/diff/rebased_resource.go @@ -38,10 +38,10 @@ func (r RebasedResource) Resource() (ctlres.Resource, error) { if t.IsResourceMatching(result) { // copy newRes and existingRes as they may be modified in place resSources := map[ctlres.FieldCopyModSource]ctlres.Resource{ - ctlres.FieldCopyModSourceNew: r.newRes.DeepCopy(), - ctlres.FieldCopyModSourceExisting: r.existingRes.DeepCopy(), + ctlres.FieldCopyModSourceNew: r.newRes, + ctlres.FieldCopyModSourceExisting: r.existingRes, // Might be useful for more advanced rebase rules like ytt-based - ctlres.FieldCopyModSource("_current"): result.DeepCopy(), + ctlres.FieldCopyModSource("_current"): result, } err := t.ApplyFromMultiple(result, resSources) diff --git a/pkg/kapp/resources/mod_field_copy.go b/pkg/kapp/resources/mod_field_copy.go index b6ebe5876..4b76499b6 100644 --- a/pkg/kapp/resources/mod_field_copy.go +++ b/pkg/kapp/resources/mod_field_copy.go @@ -39,6 +39,7 @@ func (t FieldCopyMod) ApplyFromMultiple(res Resource, srcs map[FieldCopyModSourc // Make a copy of resource, to avoid modifications // that may be done even in case when there is nothing to copy updatedRes := res.DeepCopy() + source = source.DeepCopy() updated, err := t.apply(updatedRes.unstructured().Object, source.unstructured().Object, t.Path, Path{}, srcs) if err != nil { return fmt.Errorf("FieldCopyMod for path '%s' on resource '%s': %s", t.Path.AsString(), res.Description(), err) @@ -198,7 +199,7 @@ func (t FieldCopyMod) copyIntoMap(obj map[string]interface{}, fullPath Path, src continue } - val, found, err := t.obtainValue(srcRes.unstructured().Object, fullPath) + val, found, err := t.obtainValue(srcRes.DeepCopy().unstructured().Object, fullPath) if err != nil { return false, err } else if !found {