@@ -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,17 @@ 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" }},
157+
158+ // Values set by Fleet in input packages starting on 9.1.0.
159+ {name : "inputs" , elementsEntries : []policyEntryFilter {
160+ {name : "streams" , elementsEntries : []policyEntryFilter {
161+ {name : "data_stream.type" },
162+ {name : "data_stream.elasticsearch.dynamic_dataset" },
163+ {name : "data_stream.elasticsearch.dynamic_namespace" },
164+ {name : "data_stream.elasticsearch" , onlyIfEmpty : true },
165+ }},
166+ }},
155167}
156168
157169// cleanPolicy prepares a policy YAML as returned by the download API to be compared with other
@@ -213,7 +225,7 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
213225 }
214226 }
215227 default :
216- if entry .onlyIfEmpty && ! isEmpty (v ) {
228+ if entry .onlyIfEmpty && ! isEmpty (v , entry . ignoreValues ) {
217229 continue
218230 }
219231 err := policyMap .Delete (entry .name )
@@ -229,15 +241,23 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
229241 return policyMap , nil
230242}
231243
232- func isEmpty (v any ) bool {
244+ func isEmpty (v any , ignoreValues [] any ) bool {
233245 switch v := v .(type ) {
234246 case nil :
235247 return true
236248 case []any :
237- return len (v ) == 0
249+ return len (filterIgnored ( v , ignoreValues ) ) == 0
238250 case map [string ]any :
239251 return len (v ) == 0
252+ case common.MapStr :
253+ return len (v ) == 0
240254 }
241255
242256 return false
243257}
258+
259+ func filterIgnored (v []any , ignoredValues []any ) []any {
260+ return slices .DeleteFunc (v , func (e any ) bool {
261+ return slices .Contains (ignoredValues , e )
262+ })
263+ }
0 commit comments