Skip to content

Commit fbe17a1

Browse files
author
jennybuckley
committed
Add comments
1 parent b24263b commit fbe17a1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

merge/update.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func shallowCopyManagers(managers fieldpath.ManagedFields) fieldpath.ManagedFiel
181181
return newManagers
182182
}
183183

184+
// prune will remove a list or map item, iff:
185+
// * applyingManager applied it last time
186+
// * applyingManager didn't apply it this time
187+
// * no other applier claims to manage it
184188
func (s *Updater) prune(merged typed.TypedValue, managers fieldpath.ManagedFields, applyingManager string, lastSet *fieldpath.VersionedSet) (typed.TypedValue, error) {
185189
if lastSet == nil || lastSet.Set.Empty() {
186190
return merged, nil
@@ -204,6 +208,8 @@ func (s *Updater) prune(merged typed.TypedValue, managers fieldpath.ManagedField
204208
return s.Converter.Convert(pruned, managers[applyingManager].APIVersion)
205209
}
206210

211+
// addBackOwnedItems adds back any list and map items that were removed by prune,
212+
// but other appliers (or the current applier's new config) claim to own.
207213
func (s *Updater) addBackOwnedItems(merged, pruned typed.TypedValue, managedFields fieldpath.ManagedFields, applyingManager string) (typed.TypedValue, error) {
208214
var err error
209215
managedAtVersion := map[fieldpath.APIVersion]*fieldpath.Set{}
@@ -243,6 +249,10 @@ func (s *Updater) addBackOwnedItems(merged, pruned typed.TypedValue, managedFiel
243249
return pruned, nil
244250
}
245251

252+
253+
// addBackDanglingItems makes sure that the only items removed by prune are items that were
254+
// previously owned by the currently applying manager. This will add back unowned items and items
255+
// which are owned by Updaters that shouldn't be removed.
246256
func (s *Updater) addBackDanglingItems(merged, pruned typed.TypedValue, lastSet *fieldpath.VersionedSet) (typed.TypedValue, error) {
247257
convertedPruned, err := s.Converter.Convert(pruned, lastSet.APIVersion)
248258
if err != nil {

0 commit comments

Comments
 (0)