-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manage labels in GitOps #27038
base: main
Are you sure you want to change the base?
Manage labels in GitOps #27038
Conversation
cmd/fleetctl/gitops.go
Outdated
@@ -144,6 +149,42 @@ func gitopsCommand() *cli.Command { | |||
continue | |||
} | |||
|
|||
// If we're in a team config, or a global config without `labels:` declared, | |||
// get the set of existing label names from the db. | |||
if !isGlobalConfig || (config.Labels != nil && len(config.Labels) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The distinction between nil
and 0-length array is important here. nil
means the config specifies labels:
but doesn't list any, therefore any existing labels will be deleted. A zero-length array means labels:
was not specified in the config, which we'll take to mean "don't touch existing labels". This allows backwards compatibility for existing GitOps implementations. It may seem cleaner to switch this so that nil
means no-op and empty array means "wipe everything", but this implementation is more consistent with how other top-level keys handle nil
.
See https://github.com/fleetdm/fleet/pull/27038/files#diff-b3ea9c0df50b0b532d98723f4236fa700450f1dbcd742f52f5d44797baec4a1dR190 for how this is set.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #27038 +/- ##
========================================
Coverage 63.98% 63.99%
========================================
Files 1706 1706
Lines 162797 163140 +343
Branches 4326 4326
========================================
+ Hits 104172 104404 +232
- Misses 50513 50586 +73
- Partials 8112 8150 +38
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
For #24473
Checklist for submitter
changes/
,orbit/changes/
oree/fleetd-chrome/changes
.See Changes files for more information.
Details
This PR adds the ability to manage labels via GitOps. Usage is as follows:
labels:
key is provided in the global YAML file provided to GitOps, then any labels in this list will be created (if using a new name) or updated (if using an existing name).labels:
key is provided, no changes will be made to labels. This allows backwards-compatibility; customers won't blow away all of their labels if they don't immediately uselabels:
in their YAMLAdditionally, some new validation has been added so that label usage is checked prior to application. This means that when the gitops command is run, it will verify that any labels referenced elsewhere in the YAML (e.g. by software installers or mdm profiles) exist, and will bail with an error message if they don't.