@@ -12,6 +12,7 @@ import (
1212 "os"
1313 "path/filepath"
1414 "regexp"
15+ "slices"
1516 "strings"
1617
1718 "github.com/pmezard/go-difflib/difflib"
@@ -98,6 +99,7 @@ type policyEntryFilter struct {
9899 elementsEntries []policyEntryFilter
99100 memberReplace * policyEntryReplace
100101 onlyIfEmpty bool
102+ ignoreValues []any
101103}
102104
103105type policyEntryReplace struct {
@@ -151,7 +153,7 @@ var policyEntryFilters = []policyEntryFilter{
151153 }},
152154
153155 // Namespaces may not be present in older versions of the stack.
154- {name : "namespaces" , onlyIfEmpty : true },
156+ {name : "namespaces" , onlyIfEmpty : true , ignoreValues : [] any { "default" } },
155157}
156158
157159// cleanPolicy prepares a policy YAML as returned by the download API to be compared with other
@@ -213,7 +215,7 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
213215 }
214216 }
215217 default :
216- if entry .onlyIfEmpty && ! isEmpty (v ) {
218+ if entry .onlyIfEmpty && ! isEmpty (v , entry . ignoreValues ) {
217219 continue
218220 }
219221 err := policyMap .Delete (entry .name )
@@ -229,15 +231,21 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
229231 return policyMap , nil
230232}
231233
232- func isEmpty (v any ) bool {
234+ func isEmpty (v any , ignoreValues [] any ) bool {
233235 switch v := v .(type ) {
234236 case nil :
235237 return true
236238 case []any :
237- return len (v ) == 0
239+ return len (filterIgnored ( v , ignoreValues ) ) == 0
238240 case map [string ]any :
239241 return len (v ) == 0
240242 }
241243
242244 return false
243245}
246+
247+ func filterIgnored (v []any , ignoredValues []any ) []any {
248+ return slices .DeleteFunc (v , func (e any ) bool {
249+ return slices .Contains (ignoredValues , e )
250+ })
251+ }
0 commit comments