Skip to content

Commit 203764c

Browse files
author
jennybuckley
committed
Remove empty sets from managers
1 parent 6e48806 commit 203764c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

internal/fixture/state.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,5 +259,12 @@ func (tc TestCase) Test(parser *typed.ParseableType) error {
259259
}
260260
}
261261

262+
// Fail if any empty sets are present in the managers
263+
for manager, set := range state.Managers {
264+
if set.Empty() {
265+
return fmt.Errorf("expected Managers to have no empty sets, but found one managed by %v", manager)
266+
}
267+
}
268+
262269
return nil
263270
}

merge/leaf_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,55 @@ func TestUpdateLeaf(t *testing.T) {
221221
},
222222
},
223223
},
224+
"update_remove_empty_set": {
225+
Ops: []Operation{
226+
Apply{
227+
Manager: "default",
228+
APIVersion: "v1",
229+
Object: `
230+
string: "string"
231+
`,
232+
},
233+
Update{
234+
Manager: "controller",
235+
APIVersion: "v1",
236+
Object: `
237+
string: "new string"
238+
`,
239+
},
240+
},
241+
Object: `
242+
string: "new string"
243+
`,
244+
Managed: fieldpath.ManagedFields{
245+
"controller": &fieldpath.VersionedSet{
246+
Set: _NS(
247+
_P("string"),
248+
),
249+
APIVersion: "v1",
250+
},
251+
},
252+
},
253+
"apply_remove_empty_set": {
254+
Ops: []Operation{
255+
Apply{
256+
Manager: "default",
257+
APIVersion: "v1",
258+
Object: `
259+
string: "string"
260+
`,
261+
},
262+
Apply{
263+
Manager: "default",
264+
APIVersion: "v1",
265+
Object: "",
266+
},
267+
},
268+
Object: `
269+
string: "string"
270+
`,
271+
Managed: fieldpath.ManagedFields{},
272+
},
224273
}
225274

226275
for name, test := range tests {

merge/update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ func (s *Updater) update(oldObject, newObject typed.TypedValue, version fieldpat
8585

8686
for manager, conflictSet := range conflicts {
8787
managers[manager].Set = managers[manager].Set.Difference(conflictSet.Set)
88+
if managers[manager].Set.Empty() {
89+
delete(managers, manager)
90+
}
8891
}
8992

9093
return managers, nil
@@ -112,6 +115,9 @@ func (s *Updater) Update(liveObject, newObject typed.TypedValue, version fieldpa
112115
}
113116
managers[manager].Set = managers[manager].Set.Union(compare.Modified).Union(compare.Added).Difference(compare.Removed)
114117
managers[manager].APIVersion = version
118+
if managers[manager].Set.Empty() {
119+
delete(managers, manager)
120+
}
115121
return managers, nil
116122
}
117123

@@ -138,5 +144,8 @@ func (s *Updater) Apply(liveObject, configObject typed.TypedValue, version field
138144
Set: set,
139145
APIVersion: version,
140146
}
147+
if managers[manager].Set.Empty() {
148+
delete(managers, manager)
149+
}
141150
return newObject, managers, nil
142151
}

0 commit comments

Comments
 (0)