Skip to content

Commit 7c4c2c4

Browse files
authored
Merge pull request kubernetes-sigs#6785 from chrischdi/pr-filterintent-nested-empty-map
🐛 fix structuredmerge filterintent to cleanup nested empty maps
2 parents d659d99 + 2631a8f commit 7c4c2c4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

internal/controllers/topology/cluster/structuredmerge/filterintent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func filterIntent(ctx *filterIntentInput) bool {
7979
// Ensure we are not leaving empty maps around.
8080
if v, ok := fieldCtx.value.(map[string]interface{}); ok && len(v) == 0 {
8181
delete(value, field)
82+
gotDeletions = true
8283
}
8384
}
8485
}

internal/controllers/topology/cluster/structuredmerge/filterintent_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,27 @@ func Test_filterIgnoredPaths(t *testing.T) {
167167
// we are filtering out spec.foo and then spec given that it is an empty map
168168
},
169169
},
170+
{
171+
name: "Cleanup empty nested maps",
172+
ctx: &filterIntentInput{
173+
path: contract.Path{},
174+
value: map[string]interface{}{
175+
"spec": map[string]interface{}{
176+
"bar": map[string]interface{}{
177+
"foo": "123",
178+
},
179+
},
180+
},
181+
shouldFilter: isIgnorePath(
182+
[]contract.Path{
183+
{"spec", "bar", "foo"},
184+
},
185+
),
186+
},
187+
wantValue: map[string]interface{}{
188+
// we are filtering out spec.bar.foo and then spec given that it is an empty map
189+
},
190+
},
170191
}
171192
for _, tt := range tests {
172193
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)