Skip to content

Commit ca99bda

Browse files
committed
Remove fields when unset from applied configuration if there are no other owners
1 parent 068223b commit ca99bda

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

merge/leaf_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func TestUpdateLeaf(t *testing.T) {
345345
),
346346
},
347347
},
348-
"apply_twice_dangling": {
348+
"apply_twice_remove": {
349349
Ops: []Operation{
350350
Apply{
351351
Manager: "default",
@@ -365,9 +365,7 @@ func TestUpdateLeaf(t *testing.T) {
365365
},
366366
},
367367
Object: `
368-
numeric: 1
369368
string: "new string"
370-
bool: false
371369
`,
372370
APIVersion: "v1",
373371
Managed: fieldpath.ManagedFields{
@@ -380,7 +378,7 @@ func TestUpdateLeaf(t *testing.T) {
380378
),
381379
},
382380
},
383-
"apply_twice_dangling_different_version": {
381+
"apply_twice_remove_different_version": {
384382
Ops: []Operation{
385383
Apply{
386384
Manager: "default",
@@ -400,9 +398,7 @@ func TestUpdateLeaf(t *testing.T) {
400398
},
401399
},
402400
Object: `
403-
numeric: 1
404401
string: "new string"
405-
bool: false
406402
`,
407403
APIVersion: "v1",
408404
Managed: fieldpath.ManagedFields{
@@ -462,7 +458,6 @@ func TestUpdateLeaf(t *testing.T) {
462458
},
463459
},
464460
Object: `
465-
string: "string"
466461
`,
467462
APIVersion: "v1",
468463
Managed: fieldpath.ManagedFields{},

merge/update.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func shallowCopyManagers(managers fieldpath.ManagedFields) fieldpath.ManagedFiel
212212
return newManagers
213213
}
214214

215-
// prune will remove a list or map item, iff:
215+
// prune will remove a field, list or map item, iff:
216216
// * applyingManager applied it last time
217217
// * applyingManager didn't apply it this time
218218
// * no other applier claims to manage it
@@ -240,7 +240,7 @@ func (s *Updater) prune(merged *typed.TypedValue, managers fieldpath.ManagedFiel
240240
return s.Converter.Convert(pruned, managers[applyingManager].APIVersion())
241241
}
242242

243-
// addBackOwnedItems adds back any list and map items that were removed by prune,
243+
// addBackOwnedItems adds back any fields, list and map items that were removed by prune,
244244
// but other appliers (or the current applier's new config) claim to own.
245245
func (s *Updater) addBackOwnedItems(merged, pruned *typed.TypedValue, managedFields fieldpath.ManagedFields, applyingManager string) (*typed.TypedValue, error) {
246246
var err error
@@ -281,9 +281,9 @@ func (s *Updater) addBackOwnedItems(merged, pruned *typed.TypedValue, managedFie
281281
return pruned, nil
282282
}
283283

284-
// addBackDanglingItems makes sure that the only items removed by prune are items that were
285-
// previously owned by the currently applying manager. This will add back unowned items and items
286-
// which are owned by Updaters that shouldn't be removed.
284+
// addBackDanglingItems makes sure that the fields list and map items removed by prune were
285+
// previously owned by the currently applying manager. This will add back fields list and map items
286+
// that are unowned or that are owned by Updaters and shouldn't be removed.
287287
func (s *Updater) addBackDanglingItems(merged, pruned *typed.TypedValue, lastSet fieldpath.VersionedSet) (*typed.TypedValue, error) {
288288
convertedPruned, err := s.Converter.Convert(pruned, lastSet.APIVersion())
289289
if err != nil {

typed/remove.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
9595
fieldType := t.ElementType
9696
if ft, ok := fieldTypes[k]; ok {
9797
fieldType = ft
98-
} else {
99-
if w.toRemove.Has(path) {
100-
return true
101-
}
98+
}
99+
if w.toRemove.Has(path) {
100+
return true
102101
}
103102
if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
104103
val = removeItemsWithSchema(val, subset, w.schema, fieldType)

0 commit comments

Comments
 (0)