Skip to content
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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Conversation

sgress454
Copy link
Contributor

@sgress454 sgress454 commented Mar 11, 2025

For #24473

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Details

This PR adds the ability to manage labels via GitOps. Usage is as follows:

  • If a top-level 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).
  • If no top-level 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 use labels: in their YAML

Additionally, 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.

@sgress454 sgress454 requested a review from a team as a code owner March 11, 2025 16:49
@@ -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) {
Copy link
Contributor Author

@sgress454 sgress454 Mar 11, 2025

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.

Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 74.03846% with 54 lines in your changes missing coverage. Please review.

Project coverage is 63.99%. Comparing base (25a3835) to head (0156412).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
pkg/spec/gitops.go 52.11% 22 Missing and 12 partials ⚠️
server/service/client.go 74.54% 9 Missing and 5 partials ⚠️
cmd/fleetctl/gitops.go 92.68% 4 Missing and 2 partials ⚠️
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     
Flag Coverage Δ
backend 64.75% <74.03%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants