Improve name key validation in GitOps (#44553)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [X] Added/updated automated tests
- [X] QA'd all new/changed functionality manually
  - [X] omitted `name:` from a file without `org_settings:`, got:
```
	* No `name` was provided in /tmp/testback/fleets/third-fleet.yml. If this file is intended to define org-level settings, add `org_settings:` as a top-level key. Otherwise, use `name` to specify the fleet name.
```
  - [X] omitted `name:` from a file with `org_settings:`, got no error.
  - [X] omitted `name:` from `no-team.yml`, got:
```
	* `name` must be `No Team` for `no-team.yml`
```
  - [X] omitted `name:` from `unassigned.yml`, got:
```
	* `name` must be `Unassigned` for `unassigned.yml`
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved error messages when GitOps YAML files omit the required
`name` field, with specific remediation guidance tailored to each
configuration file type
* Enhanced validation error messaging when top-level `org_settings` is
missing or incorrectly placed, providing clearer instructions on
required YAML structure

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Scott Gress
2026-05-11 13:49:02 -05:00
committed by GitHub
parent 8b779110a8
commit 348fa47c84
4 changed files with 49 additions and 9 deletions
+10 -3
View File
@@ -468,10 +468,10 @@ func GitOpsFromFile(filePath, baseDir string, appConfig *fleet.EnrichedAppConfig
// If the file is no-team.yml, the name must be "No team".
switch {
case filepath.Base(filePath) == "no-team.yml" && !result.IsNoTeam():
multiError = multierror.Append(multiError, fmt.Errorf("file %q must have team name 'No Team'", filePath))
multiError = multierror.Append(multiError, errors.New("`name` must be `No Team` for `no-team.yml`"))
return result, multiError.ErrorOrNil()
case filepath.Base(filePath) == "unassigned.yml" && !result.IsUnassignedTeam():
multiError = multierror.Append(multiError, fmt.Errorf("file %q must have team name 'Unassigned'", filePath))
multiError = multierror.Append(multiError, errors.New("`name` must be `Unassigned` for `unassigned.yml`"))
return result, multiError.ErrorOrNil()
case result.IsNoTeam() && filepath.Base(filePath) != "no-team.yml":
multiError = multierror.Append(multiError, fmt.Errorf("file `%s` for No Team must be named `no-team.yml`", filePath))
@@ -496,7 +496,14 @@ func GitOpsFromFile(filePath, baseDir string, appConfig *fleet.EnrichedAppConfig
multiError = parseTeamSettings(settingsRaw, result, baseDir, filePath, multiError)
}
default:
multiError = multierror.Append(multiError, errors.New("if `name` is not provided, 'org_settings' is required"))
switch filepath.Base(filePath) {
case "no-team.yml":
multiError = multierror.Append(multiError, errors.New("`name` must be `No Team` for `no-team.yml`"))
case "unassigned.yml":
multiError = multierror.Append(multiError, errors.New("`name` must be `Unassigned` for `unassigned.yml`"))
default:
multiError = multierror.Append(multiError, fmt.Errorf("No `name` was provided in %s. If this file is intended to define org-level settings, add `org_settings:` as a top-level key. Otherwise, use `name` to specify the fleet name.", filePath))
}
}
for _, topKey := range topKeys {