@@ -0,0 +1 @@
|
||||
- Fixed missing empty host lists on manual labels in gitops
|
||||
+8
-2
@@ -675,8 +675,14 @@ func parseLabels(top map[string]json.RawMessage, result *GitOps, baseDir string,
|
||||
if l.Name == "" {
|
||||
multiError = multierror.Append(multiError, errors.New("name is required for each label"))
|
||||
}
|
||||
if l.Query == "" && len(l.Hosts) == 0 && l.HostVitalsCriteria == nil {
|
||||
multiError = multierror.Append(multiError, errors.New("a SQL query, hosts list or host vitals criteria is required for each label"))
|
||||
|
||||
if l.LabelMembershipType != fleet.LabelMembershipTypeManual && l.Query == "" && l.HostVitalsCriteria == nil {
|
||||
multiError = multierror.Append(multiError, errors.New("a SQL query or host vitals criteria is required for each non-manual label"))
|
||||
}
|
||||
|
||||
// Manual labels can have empty hosts lists, just make sure we initialize the empty list
|
||||
if l.LabelMembershipType == fleet.LabelMembershipTypeManual && l.Hosts == nil {
|
||||
l.Hosts = []string{}
|
||||
}
|
||||
// Don't use non-ASCII
|
||||
if !isASCII(l.Name) {
|
||||
|
||||
@@ -366,6 +366,21 @@ policies:
|
||||
assert.ErrorContains(t, err, "duplicate policy names")
|
||||
}
|
||||
|
||||
func TestManualLabelEmptyHostList(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := getGlobalConfig([]string{})
|
||||
config += `
|
||||
labels:
|
||||
- name: TestLabel
|
||||
description: Label for testing
|
||||
hosts:
|
||||
label_membership_type: manual`
|
||||
|
||||
gitops, err := gitOpsFromString(t, config)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, gitops.Labels[0].Hosts)
|
||||
}
|
||||
|
||||
func TestDuplicateQueryNames(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := getGlobalConfig([]string{"queries"})
|
||||
|
||||
Reference in New Issue
Block a user