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 {