Skip to content

Commit

Permalink
Do not deep copy source resources while rebasing
Browse files Browse the repository at this point in the history
Only copy them when required

Signed-off-by: Praveen Rewar <[email protected]>
  • Loading branch information
praveenrewar committed Nov 17, 2023
1 parent de79e5a commit 5fd1ca2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/kapp/diff/rebased_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/kapp/resources/mod_field_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5fd1ca2

Please sign in to comment.