Skip to content

Commit

Permalink
Add comment that keeping fields is intentional
Browse files Browse the repository at this point in the history
- Preserving the Type and Metas fields on merge overlay operations is
  intentional in the anticipation that we may need them later for type
checking
- We did not change logic to preserve fields on overlay replace
  operations, but anticipate we may need to preserve some fields later
on.
Signed-off-by: John Ryan <[email protected]>
  • Loading branch information
cari-lynn authored and pivotaljohn committed Apr 14, 2021
1 parent a1fa9e9 commit 2f89b7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/yttlibrary/overlay/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (o Op) mergeArrayItem(
}
}
if replace {
// left side type and metas are preserved
err := leftArray.Items[leftIdx].SetValue(newItem.Value)
if err != nil {
return err
Expand Down Expand Up @@ -116,6 +117,8 @@ func (o Op) replaceArrayItem(
return err
}

// left side fields are not preserved.
// probably need to rethink how to merge left and right once those fields are needed
leftArray.Items[leftIdx] = newItem.DeepCopy()
err = leftArray.Items[leftIdx].SetValue(newVal)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/yttlibrary/overlay/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (o Op) mergeMapItem(leftMap *yamlmeta.Map, newItem *yamlmeta.MapItem,
}
}
if replace {
// left side type and metas are preserved
err := leftMap.Items[leftIdx].SetValue(newItem.Value)
if err != nil {
return err
Expand Down Expand Up @@ -115,6 +116,8 @@ func (o Op) replaceMapItem(leftMap *yamlmeta.Map, newItem *yamlmeta.MapItem,
return err
}

// left side fields are not preserved.
// probably need to rethink how to merge left and right once those fields are needed
leftMap.Items[leftIdx] = newItem.DeepCopy()
err = leftMap.Items[leftIdx].SetValue(newVal)
if err != nil {
Expand Down

0 comments on commit 2f89b7c

Please sign in to comment.