Add include_all label scope to GitOps and fleetctl (#41566)#44534
Add include_all label scope to GitOps and fleetctl (#41566)#44534juan-fdz-hawa wants to merge 3 commits intomainfrom
Conversation
Wires labels_include_all to GitOps and fleetctl for policies and reports.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughThis PR adds support for Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (5)
changes/41566-policy-report-labels-gitops (1)
1-1: ⚡ Quick winUse user-facing language in the changelog entry.
The word "Wires" is developer jargon that doesn't clearly communicate the user-visible change. Changelog entries should describe what users can now do, not implementation details.
📝 Suggested rewording for clarity
-- Wires labels_include_all to GitOps/fleetctl for policies and reports. +- Added support for `labels_include_all` label scope in GitOps and fleetctl for policies and reports.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@changes/41566-policy-report-labels-gitops` at line 1, Change the changelog entry that currently reads "Wires labels_include_all to GitOps/fleetctl for policies and reports" to user-facing language that describes the new capability; for example, replace "Wires" with a clear phrase such as "Add support for" or "Allow users to include" so the entry reads like "Add support for labels_include_all in GitOps/fleetctl for policies and reports" (referencing the labels_include_all flag, GitOps/fleetctl integration, and the policies and reports feature to locate the entry).cmd/fleetctl/fleetctl/get_test.go (1)
1891-1945: ⚡ Quick winAdd one default table-output assertion for
labels_include_all.These tests cover
--yaml/--json, but the table behavior added at Line 352 incmd/fleetctl/fleetctl/get.goisn’t exercised yet. A plainfleetctl get reportsassertion forlabels_include_allwould close that gap.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/fleetctl/fleetctl/get_test.go` around lines 1891 - 1945, TestGetReportsLabelsIncludeAll currently asserts only YAML/JSON outputs but not the default table output; add a table-output assertion by calling RunAppForTest(t, []string{"get", "reports"}) and asserting the returned string contains the labels (e.g. assert.Contains(t, out, "labelA") and assert.Contains(t, out, "labelB") or a combined "labelA,labelB" as appropriate) so the new table formatting in the get reports command is exercised; update TestGetReportsLabelsIncludeAll to include these assert calls referencing RunAppForTest and the "get reports" invocation.server/service/queries.go (1)
824-827: ⚡ Quick winReturn the missing label names here.
label not foundis too generic now that bothlabels_include_anyandlabels_include_allfunnel through this branch. Including the missing names would make GitOps/API failures much easier to fix.Suggested change
- for _, name := range allLabelNames { - if _, ok := labelsMap[name]; !ok { - return nil, ctxerr.New(ctx, "label not found") - } - } + missing := make([]string, 0) + for _, name := range allLabelNames { + if _, ok := labelsMap[name]; !ok { + missing = append(missing, name) + } + } + if len(missing) > 0 { + return nil, ctxerr.New(ctx, fmt.Sprintf("labels not found: %s", strings.Join(missing, ", "))) + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/service/queries.go` around lines 824 - 827, The loop over allLabelNames that currently returns a generic ctxerr.New(ctx, "label not found") should collect the actual missing label names (e.g., build a slice missing := []string{} when iterating for _, name := range allLabelNames and checking labelsMap[name]) and return an error that includes them (e.g., fmt.Join or formatted message) instead of the generic string; update the return to use ctxerr.Newf or ctxerr.New with a formatted message like "labels not found: <names>" so callers of the function that contains this loop (the block using labelsMap and allLabelNames) get the specific missing label names.cmd/fleetctl/fleetctl/gitops_test.go (1)
295-334: ⚡ Quick winAdd a free-tier
labels_include_allGitOps test.These new cases only exercise
labels_include_allwith a premium license. The existing free-tier coverage still only protectslabels_include_any, so the new license-gated branch can regress without a failing test.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/fleetctl/fleetctl/gitops_test.go` around lines 295 - 334, Add a new test function (e.g., TestGitOpsQueryLabelsIncludeAllFreeTier) that mirrors TestGitOpsQueryLabelsIncludeAllUnknownLabel but sets the license to fleet.TierFree (use RunServerWithMockedDS/TestServerOpts like the existing test), creates the same GitOps YAML that uses labels_include_all, calls RunAppNoChecks with that file, and assert that it errors and the error message mentions the license/gating of labels_include_all (check Error and ErrorContains against text including "labels_include_all" and "license" or "premium"). This ensures the labels_include_all license-gated branch is covered; reference the existing TestGitOpsQueryLabelsIncludeAllUnknownLabel, labels_include_all, RunServerWithMockedDS, and RunAppNoChecks to locate where to add the duplicate test.server/service/integration_enterprise_test.go (1)
29473-29493: ⚡ Quick winAdd explicit non-persistence assertions for rejected single-spec GitOps requests
These negative tests currently validate only the error response. Please also assert the rejected policy/query names were not created, so partial-write regressions are caught (same guarantee you already enforce in the batch test).
Also applies to: 29589-29599
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/service/integration_enterprise_test.go` around lines 29473 - 29493, Add explicit assertions that the rejected spec names were not persisted: after each POST that returns BadRequest (the requests captured in rejSpecResp and rejSpecResp2 sent with fleet.ApplyPolicySpecsRequest containing fleet.PolicySpec named "spec-rej-any-"+t.Name() and "spec-rej-excl-"+t.Name()), call the API to fetch specs (e.g., via s.Do GET /api/latest/fleet/spec/policies or the single-spec read endpoint) and assert the returned list does not contain those policy names; use the same helper extractServerErrorText and compare against the PolicySpec.Name values and fleet.ErrPolicyConflictingLabels to ensure no partial write occurred.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@changes/41566-policy-report-labels-gitops`:
- Line 1: Change the changelog entry that currently reads "Wires
labels_include_all to GitOps/fleetctl for policies and reports" to user-facing
language that describes the new capability; for example, replace "Wires" with a
clear phrase such as "Add support for" or "Allow users to include" so the entry
reads like "Add support for labels_include_all in GitOps/fleetctl for policies
and reports" (referencing the labels_include_all flag, GitOps/fleetctl
integration, and the policies and reports feature to locate the entry).
In `@cmd/fleetctl/fleetctl/get_test.go`:
- Around line 1891-1945: TestGetReportsLabelsIncludeAll currently asserts only
YAML/JSON outputs but not the default table output; add a table-output assertion
by calling RunAppForTest(t, []string{"get", "reports"}) and asserting the
returned string contains the labels (e.g. assert.Contains(t, out, "labelA") and
assert.Contains(t, out, "labelB") or a combined "labelA,labelB" as appropriate)
so the new table formatting in the get reports command is exercised; update
TestGetReportsLabelsIncludeAll to include these assert calls referencing
RunAppForTest and the "get reports" invocation.
In `@cmd/fleetctl/fleetctl/gitops_test.go`:
- Around line 295-334: Add a new test function (e.g.,
TestGitOpsQueryLabelsIncludeAllFreeTier) that mirrors
TestGitOpsQueryLabelsIncludeAllUnknownLabel but sets the license to
fleet.TierFree (use RunServerWithMockedDS/TestServerOpts like the existing
test), creates the same GitOps YAML that uses labels_include_all, calls
RunAppNoChecks with that file, and assert that it errors and the error message
mentions the license/gating of labels_include_all (check Error and ErrorContains
against text including "labels_include_all" and "license" or "premium"). This
ensures the labels_include_all license-gated branch is covered; reference the
existing TestGitOpsQueryLabelsIncludeAllUnknownLabel, labels_include_all,
RunServerWithMockedDS, and RunAppNoChecks to locate where to add the duplicate
test.
In `@server/service/integration_enterprise_test.go`:
- Around line 29473-29493: Add explicit assertions that the rejected spec names
were not persisted: after each POST that returns BadRequest (the requests
captured in rejSpecResp and rejSpecResp2 sent with fleet.ApplyPolicySpecsRequest
containing fleet.PolicySpec named "spec-rej-any-"+t.Name() and
"spec-rej-excl-"+t.Name()), call the API to fetch specs (e.g., via s.Do GET
/api/latest/fleet/spec/policies or the single-spec read endpoint) and assert the
returned list does not contain those policy names; use the same helper
extractServerErrorText and compare against the PolicySpec.Name values and
fleet.ErrPolicyConflictingLabels to ensure no partial write occurred.
In `@server/service/queries.go`:
- Around line 824-827: The loop over allLabelNames that currently returns a
generic ctxerr.New(ctx, "label not found") should collect the actual missing
label names (e.g., build a slice missing := []string{} when iterating for _,
name := range allLabelNames and checking labelsMap[name]) and return an error
that includes them (e.g., fmt.Join or formatted message) instead of the generic
string; update the return to use ctxerr.Newf or ctxerr.New with a formatted
message like "labels not found: <names>" so callers of the function that
contains this loop (the block using labelsMap and allLabelNames) get the
specific missing label names.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 86db80c1-58bc-4b6d-91b0-7cc95e932b01
📒 Files selected for processing (13)
changes/41566-policy-report-labels-gitopscmd/fleetctl/fleetctl/get.gocmd/fleetctl/fleetctl/get_test.gocmd/fleetctl/fleetctl/gitops.gocmd/fleetctl/fleetctl/gitops_test.goserver/datastore/mysql/policies.goserver/datastore/mysql/policies_test.goserver/fleet/policies.goserver/fleet/queries.goserver/service/global_policies.goserver/service/integration_core_test.goserver/service/integration_enterprise_test.goserver/service/queries.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #44534 +/- ##
==========================================
- Coverage 66.79% 66.79% -0.01%
==========================================
Files 2637 2637
Lines 212132 212178 +46
Branches 9437 9437
==========================================
+ Hits 141688 141718 +30
- Misses 57578 57590 +12
- Partials 12866 12870 +4
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:
|
Related issue: Resolves #41566
Wires labels_include_all to GitOps and fleetctl for policies and reports.
Checklist for submitter
If some of the following don't apply, delete the relevant line.
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Testing
Summary by CodeRabbit
Release Notes
fleetctl getcommands to display include-all label settings in table, YAML, and JSON formats