Skip to content

Warn when labels key appears in no-team/unassigned GitOps files - #44865

Merged
sharon-fdm merged 7 commits into
mainfrom
fix-42522-reject-labels-in-no-team
May 11, 2026
Merged

Warn when labels key appears in no-team/unassigned GitOps files#44865
sharon-fdm merged 7 commits into
mainfrom
fix-42522-reject-labels-in-no-team

Conversation

@sharon-fdm

@sharon-fdm sharon-fdm commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #42522

Changes

When labels: appears in a no-team/unassigned GitOps file, log a warning and skip label parsing. This matches the existing pattern used by agent_options and reports in no-team files.

A warning (not an error) is used intentionally to avoid breaking existing customer GitOps pipelines that may already have labels: in their no-team file.

After fix:

[!] 'labels' is not supported in unassigned.yml. This key will be ignored.

Testing

Manual testing

Built fleetctl from the fixed branch against a local Fleet server (premium license).

Scenario Result
unassigned.yml dry-run Warning printed, succeeds
unassigned.yml real run Warning printed, succeeds
no-team.yml dry-run Warning printed, succeeds
no-team.yml real run Warning printed, succeeds
unassigned.yml without labels No warning, succeeds (no regression)

Unit tests

  • TestLabelsIgnoredInNoTeamFile: Sub-tests for both no-team.yml and unassigned.yml assert: (1) no error, (2) LabelsPresent is true, (3) no labels parsed, (4) warning logged.

Closes #42522. The labels: top-level key in no-team.yml or unassigned.yml
was silently accepted. Now it logs a warning and ignores the key, matching
the existing pattern for agent_options and reports.
@sharon-fdm
sharon-fdm marked this pull request as ready for review May 6, 2026 18:50
@sharon-fdm
sharon-fdm requested a review from a team as a code owner May 6, 2026 18:50
Copilot AI review requested due to automatic review settings May 6, 2026 18:50

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

GitOpsFromFile now marks a top-level labels: key as present but, for No Team files (no-team.yml/unassigned.yml), logs a warning and ignores the labels key instead of parsing it; for other files it still parses labels. A unit test (TestLabelsIgnoredInNoTeamFile) was added to verify parsing succeeds, LabelsPresent is true, Labels stays empty, and a warning mentioning the filename is emitted. A changelog bullet documents the new warning.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: warning when a labels key appears in no-team/unassigned GitOps files, which is the core objective of the linked issue.
Linked Issues check ✅ Passed The PR successfully implements the requirement from issue #42522: detect labels in no-team/unassigned files, log a warning, and skip parsing while preserving LabelsPresent status, matching existing patterns.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #42522: code changes handle the specific scenario, tests verify the new warning behavior, and changelog entries document the fix.
Description check ✅ Passed PR description includes related issue, detailed change explanation, and comprehensive testing (manual + unit tests), but omits several checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-42522-reject-labels-in-no-team

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/spec/gitops_test.go (1)

2417-2437: ⚡ Quick win

Consider adding the same assertion for unassigned.yml path.

The parser path also treats unassigned.yml as no-team via coercion, so a sibling test would guard that branch and warning text (unassigned.yml) against regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/spec/gitops_test.go` around lines 2417 - 2437, Extend
TestLabelsIgnoredInNoTeamFile to also verify the parser behavior for an
"unassigned.yml" filename: create a second temp file via
createNamedFileOnTempDir using the same config but named "unassigned.yml", call
GitOpsFromFile with that unassignedPath/unassignedBasePath (reusing the
captureLogf/logMessages setup), assert LabelsPresent is false and Labels is
empty for the returned gitops, and assert the logged warning contains "'labels'
is not supported in unassigned.yml" to cover the coerced no-team branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/spec/gitops_test.go`:
- Around line 2417-2437: Extend TestLabelsIgnoredInNoTeamFile to also verify the
parser behavior for an "unassigned.yml" filename: create a second temp file via
createNamedFileOnTempDir using the same config but named "unassigned.yml", call
GitOpsFromFile with that unassignedPath/unassignedBasePath (reusing the
captureLogf/logMessages setup), assert LabelsPresent is false and Labels is
empty for the returned gitops, and assert the logged warning contains "'labels'
is not supported in unassigned.yml" to cover the coerced no-team branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e24c95e8-1768-46c2-b8a3-4cd58895371c

📥 Commits

Reviewing files that changed from the base of the PR and between 3fe00b8 and a637057.

📒 Files selected for processing (2)
  • pkg/spec/gitops.go
  • pkg/spec/gitops_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates GitOps file parsing to handle a labels: top-level key in no-team/unassigned GitOps YAMLs by warning and ignoring the key, and adds a unit test to validate the behavior.

Changes:

  • Log a warning and skip label parsing when labels: appears in no-team/unassigned GitOps files.
  • Add a unit test to ensure labels are not parsed and that a warning is emitted.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/spec/gitops.go Adds an IsNoTeam() guard around label parsing and logs a warning when labels: is present in no-team/unassigned files.
pkg/spec/gitops_test.go Adds TestLabelsIgnoredInNoTeamFile to validate warning + ignore behavior for labels: in a no-team file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/spec/gitops.go
Comment thread pkg/spec/gitops.go
Comment thread pkg/spec/gitops_test.go Outdated
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.79%. Comparing base (bfb6f3b) to head (906f9b1).
⚠️ Report is 104 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44865      +/-   ##
==========================================
+ Coverage   66.66%   66.79%   +0.12%     
==========================================
  Files        2672     2678       +6     
  Lines      214802   216894    +2092     
  Branches     9946     9946              
==========================================
+ Hits       143206   144877    +1671     
- Misses      58562    58848     +286     
- Partials    13034    13169     +135     
Flag Coverage Δ
backend 68.66% <100.00%> (+0.12%) ⬆️

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.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/spec/gitops_test.go`:
- Around line 2431-2433: The test currently asserts that gitops.LabelsPresent is
true for no-team files, but for unsupported/ignored labels in no-team mode it
should be false; update the assertion in the test checking gitops.LabelsPresent
to assert false (keep the following assert.Empty(t, gitops.Labels) unchanged) so
the test correctly guards against parsing labels in no-team files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 511354af-6261-4053-a540-37a9545ca14f

📥 Commits

Reviewing files that changed from the base of the PR and between a637057 and 625e9ab.

📒 Files selected for processing (1)
  • pkg/spec/gitops_test.go

Comment thread pkg/spec/gitops_test.go Outdated
Address review feedback:
- Return an error (via multiError) instead of just logging a warning,
  matching the issue requirement to "fail with an error"
- Set LabelsPresent = true unconditionally when the key exists, keeping
  its semantics consistent ("key was in the YAML")
- Add unassigned.yml sub-test alongside no-team.yml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/spec/gitops.go (1)

523-530: 💤 Low value

Behavioral asymmetry between labels and other no-team-unsupported keys

parseAgentOptions (lines 884–889) and parseReports (lines 1727–1731) silently log a warning and proceed for no-team files, while labels now appends a hard error that aborts the run. This means agent_options: or reports: in a no-team file produces a non-fatal warning but labels: causes a CI failure. This is intentional per the post-review commit message, but a future caller may want to standardize the treatment of all unsupported keys (error vs warning).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/spec/gitops.go` around lines 523 - 530, The handling of 'labels' is
inconsistent: when result.IsNoTeam() the code currently appends a hard error,
while parseAgentOptions and parseReports only log a warning; update the labels
branch in the if block that sets result.LabelsPresent (around parseLabels) so
that for no-team files it mirrors the other handlers — call logFn to emit a
warning (include filepath.Base(filePath) and context) and do not append to
multiError; leave the else path to call parseLabels as before. Reference:
result.IsNoTeam(), result.LabelsPresent, parseLabels, logFn, and filePath.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/spec/gitops.go`:
- Around line 523-530: The handling of 'labels' is inconsistent: when
result.IsNoTeam() the code currently appends a hard error, while
parseAgentOptions and parseReports only log a warning; update the labels branch
in the if block that sets result.LabelsPresent (around parseLabels) so that for
no-team files it mirrors the other handlers — call logFn to emit a warning
(include filepath.Base(filePath) and context) and do not append to multiError;
leave the else path to call parseLabels as before. Reference: result.IsNoTeam(),
result.LabelsPresent, parseLabels, logFn, and filePath.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6116cdfc-c264-46da-8c7c-91c0b6438807

📥 Commits

Reviewing files that changed from the base of the PR and between 625e9ab and 20877ce.

📒 Files selected for processing (2)
  • pkg/spec/gitops.go
  • pkg/spec/gitops_test.go

@sharon-fdm

Copy link
Copy Markdown
Collaborator Author

Re: CodeRabbit nitpick on behavioral asymmetry between labels and agent_options/reports in no-team files:

The asymmetry is intentional. The ticket (#42522) explicitly requires an error: "Fail with an error like we do for any other unsupported top-level key." A hard error is also the better UX here — silently ignoring labels: in a GitOps pipeline can mislead users into thinking their labels are being applied when they're not. Failing loudly forces them to fix the YAML, which is the correct long-term state.

@juan-fdz-hawa juan-fdz-hawa self-assigned this May 7, 2026
@juan-fdz-hawa

Copy link
Copy Markdown
Contributor

Changes LGTM, you are missing the changes file

Use a warning (logFn) instead of a hard error to avoid breaking existing
customer GitOps pipelines that happen to have labels: in their no-team
file. This matches the existing pattern used by agent_options and reports.
Also adds the changelog file.
@sharon-fdm

sharon-fdm commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

@sgress454 — After thinking about this more, I'm switching from a hard error to a warning. Customers with existing labels: in their no-team/unassigned files would immediately see their GitOps pipelines break on upgrade, even though the key was already being silently ignored. A warning surfaces the issue without breaking their flow — and it's consistent with how agent_options and reports are already handled in no-team files.

@sharon-fdm sharon-fdm changed the title Reject labels key in no-team/unassigned GitOps files Warn when labels key appears in no-team/unassigned GitOps files May 8, 2026
@sharon-fdm

Copy link
Copy Markdown
Collaborator Author

@juan-fdz-hawa , changelog added.

@juan-fdz-hawa juan-fdz-hawa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should standardize how we handle grammar violations like this. My understanding is that we should throw an error rather than a warning, as users tend to ignore warnings (though the First Impressions team may have the final say here). The code changes themselves look good, so I'm approving this for now.

@sharon-fdm
sharon-fdm merged commit 89517cc into main May 11, 2026
59 checks passed
@sharon-fdm
sharon-fdm deleted the fix-42522-reject-labels-in-no-team branch May 11, 2026 13:55
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.

Top-level "labels:" key incorrectly allowed in no-team.yml / unassigned.yml

3 participants