Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/install/stack_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ package install

const (
// DefaultStackVersion is the default version of the stack
DefaultStackVersion = "9.0.4"
DefaultStackVersion = "9.1.0"
)
28 changes: 24 additions & 4 deletions internal/testrunner/runners/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"

"github.com/pmezard/go-difflib/difflib"
Expand Down Expand Up @@ -98,6 +99,7 @@ type policyEntryFilter struct {
elementsEntries []policyEntryFilter
memberReplace *policyEntryReplace
onlyIfEmpty bool
ignoreValues []any
}

type policyEntryReplace struct {
Expand Down Expand Up @@ -151,7 +153,17 @@ var policyEntryFilters = []policyEntryFilter{
}},

// Namespaces may not be present in older versions of the stack.
{name: "namespaces", onlyIfEmpty: true},
{name: "namespaces", onlyIfEmpty: true, ignoreValues: []any{"default"}},

// Values set by Fleet in input packages starting on 9.1.0.
{name: "inputs", elementsEntries: []policyEntryFilter{
{name: "streams", elementsEntries: []policyEntryFilter{
{name: "data_stream.type"},
{name: "data_stream.elasticsearch.dynamic_dataset"},
{name: "data_stream.elasticsearch.dynamic_namespace"},
{name: "data_stream.elasticsearch", onlyIfEmpty: true},
}},
}},
}

// cleanPolicy prepares a policy YAML as returned by the download API to be compared with other
Expand Down Expand Up @@ -213,7 +225,7 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
}
}
default:
if entry.onlyIfEmpty && !isEmpty(v) {
if entry.onlyIfEmpty && !isEmpty(v, entry.ignoreValues) {
continue
}
err := policyMap.Delete(entry.name)
Expand All @@ -229,15 +241,23 @@ func cleanPolicyMap(policyMap common.MapStr, entries []policyEntryFilter) (commo
return policyMap, nil
}

func isEmpty(v any) bool {
func isEmpty(v any, ignoreValues []any) bool {
switch v := v.(type) {
case nil:
return true
case []any:
return len(v) == 0
return len(filterIgnored(v, ignoreValues)) == 0
case map[string]any:
return len(v) == 0
case common.MapStr:
return len(v) == 0
}

return false
}

func filterIgnored(v []any, ignoredValues []any) []any {
return slices.DeleteFunc(v, func(e any) bool {
return slices.Contains(ignoredValues, e)
})
}
9 changes: 9 additions & 0 deletions internal/testrunner/runners/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ id: "2e19c1c4-185b-11ef-a7fc-43855f39047f"
`,
found: `
namespaces: []
`,
equal: true,
},
{
title: "clean namespaces if default",
expected: `
`,
found: `
namespaces: [default]
`,
equal: true,
},
Expand Down