Skip to content

Move targets and secret variables to server/fleet/ - #46196

Merged
lucasmrod merged 4 commits into
mainfrom
move-targets-and-secret-variables
Jun 3, 2026
Merged

Move targets and secret variables to server/fleet/#46196
lucasmrod merged 4 commits into
mainfrom
move-targets-and-secret-variables

Conversation

@lucasmrod

@lucasmrod lucasmrod commented May 26, 2026

Copy link
Copy Markdown
Member

Resolves #36087 (one of several PRs).

Testing

  • QA'd all new/changed functionality manually.

Summary by CodeRabbit

  • New Features

    • Dry-run support when creating secret variables.
  • Improvements

    • Standardized API models for secret-variables and targets for more consistent behavior.
    • List secret variables now includes pagination metadata.
    • More consistent error reporting across secret-variables and targets APIs.
    • Target search/count behavior refined: pre-selected built-in labels are omitted as expected.
  • Tests

    • Integration tests updated to validate the new request/response behavior and target-selection logic.

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 16:00
@lucasmrod
lucasmrod requested a review from a team as a code owner May 26, 2026 16:00

@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.

@lucasmrod lucasmrod changed the title Move targets and secret variables Move targets and secret variables to server/fleet/ May 26, 2026

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 moves the Go API request/response types for “targets” and “secret variables” endpoints out of server/service/ and into server/fleet/, so Go clients (e.g. fleetctl, Orbit, etc.) can depend on server/fleet types without importing server/service code.

Changes:

  • Moved targets request/response structs (and related search result structs + JSON marshal logic) to server/fleet/api_targets.go.
  • Moved secret variables request/response structs to server/fleet/api_secret_variables.go.
  • Updated service endpoints, router registrations, clients, and integration tests to use the new fleet.* types.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/service/targets.go Switch endpoints to fleet.SearchTargetsRequest/Response and fleet.CountTargetsRequest/Response; remove now-internal service-local types.
server/service/secret_variables.go Switch endpoints to fleet.*SecretVariables* request/response types; remove service-local types.
server/service/handler.go Update route registrations to use fleet.*Request{} types for decoding.
server/service/client_targets.go Update client request/response types for /fleet/targets.
server/service/client_secret_variables.go Update client request/response types for secret variables spec endpoint.
server/service/integration_core_test.go Update tests to use moved fleet.* request/response types.
server/service/integration_enterprise_test.go Update tests to use moved fleet.* request/response types.
server/service/integration_mdm_test.go Update tests to use moved fleet.* request/response types.
server/service/integration_mdm_profiles_test.go Update tests to use moved fleet.* request/response types.
server/service/integration_mdm_ddm_test.go Update tests to use moved fleet.* request/response types.
server/fleet/api_targets.go New home for targets API request/response structs and team search result JSON marshaling logic.
server/fleet/api_secret_variables.go New home for secret variables API request/response structs.

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

Comment thread server/fleet/api_targets.go Outdated
@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds fleet DTOs for targets (search/count) and secret-variables (create/create single/list/delete), implements TeamSearchResult JSON (marshal/unmarshal), and updates server route bindings, endpoint implementations, client calls, and tests to use the new fleet types across search/count and secret-variable flows.

Possibly related PRs

  • fleetdm/fleet#44965: Also touches the custom variables / secret-variables API surface and frontend controls integration.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description is minimal, missing key details about the changes made and rationale for moving types to server/fleet. Add detailed description explaining why the API request/response types were moved to server/fleet, which dependencies are removed, and testing scope. Confirm the changes/files checklist status.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly describes the main refactoring objective: moving targets and secret variables API definitions to the server/fleet package.
Linked Issues check ✅ Passed PR implements core objective of moving response types from server/service to server/fleet to prevent unnecessary fleetctl dependencies on server/service package.
Out of Scope Changes check ✅ Passed All changes are in-scope; they focus on moving API request/response types to server/fleet and updating related endpoints/handlers accordingly, aligning with issue #36087 goals.

✏️ 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 move-targets-and-secret-variables

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.

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 `@server/fleet/api_targets.go`:
- Around line 36-63: The MarshalJSON implementation for TeamSearchResult
dereferences the embedded Team/TeamConfig unconditionally and can panic for a
zero-value result; update TeamSearchResult.MarshalJSON to guard against nil
before using t.Config/t.Team (check if t.Config!=nil or t.Team!=nil) and assign
a zero-value TeamConfig when nil (instead of dereferencing), ensuring
HostResponsesForHostsCheap(t.Hosts) and other fields are populated only from
safe, non-nil sources.
🪄 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: 0c20c3f6-1081-4cb6-8ebe-a24b44f3a535

📥 Commits

Reviewing files that changed from the base of the PR and between e2df64b and c6149ad.

📒 Files selected for processing (12)
  • server/fleet/api_secret_variables.go
  • server/fleet/api_targets.go
  • server/service/client_secret_variables.go
  • server/service/client_targets.go
  • server/service/handler.go
  • server/service/integration_core_test.go
  • server/service/integration_enterprise_test.go
  • server/service/integration_mdm_ddm_test.go
  • server/service/integration_mdm_profiles_test.go
  • server/service/integration_mdm_test.go
  • server/service/secret_variables.go
  • server/service/targets.go

Comment thread server/fleet/api_targets.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.92929% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.84%. Comparing base (d00e1ab) to head (966e16d).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
server/fleet/api_targets.go 93.75% 2 Missing and 2 partials ⚠️
server/service/client_targets.go 0.00% 2 Missing ⚠️
server/service/targets.go 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46196      +/-   ##
==========================================
- Coverage   66.91%   66.84%   -0.07%     
==========================================
  Files        2834     2781      -53     
  Lines      224966   223877    -1089     
  Branches    11517    10916     -601     
==========================================
- Hits       150527   149658     -869     
+ Misses      60782    60559     -223     
- Partials    13657    13660       +3     
Flag Coverage Δ
backend 68.62% <92.92%> (+<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.

MatchQuery string `json:"query"`
// QueryID is the ID of a saved query to run (used to determine if this is a
// query that observers can run).
QueryID *uint `json:"query_id" renameto:"report_id"`

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.

Since you are touching all users of SearchTargetsRequest might as well just rename this to ReportID and drop the rename decorator.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What do you mean? AFAICS we need to support both (query_id and report_id)

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.

Yeah you are right

type TargetsData struct {
Hosts []*HostResponse `json:"hosts"`
Labels []LabelSearchResult `json:"labels"`
Teams []TeamSearchResult `json:"teams" renameto:"fleets"`

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.

Ditto


type CountTargetsRequest struct {
Selected HostTargets `json:"selected"`
QueryID *uint `json:"query_id" renameto:"report_id"`

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.

Ditto

@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.

LGTM!
I left one optional suggestion about dropping the rename decorator on a few of the requests. It’s definitely not a dealbreaker, so I'll leave it up to you whether you want to tackle it now or skip it.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: aggregate-result

Failed stage: Check for failures [❌]

Failed test name: vuln-mysql8.0.44

Failure summary:

The action failed in the status-aggregation step that scans downloaded status artifacts and exits
non-zero if any contain fail.
- The status file ./vuln-mysql8.0.44-status/status contained fail, so
the workflow marked the test vuln-mysql8.0.44 as failed.
- As a result, the script printed ❌ One or
more test jobs failed: vuln-mysql8.0.44 and exited with code 1, causing the GitHub Action to fail.

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

119:  Artifact download completed successfully.
120:  Extracting artifact entry: /home/runner/work/fleet/fleet/scripts-status/status
121:  Artifact download completed successfully.
122:  Extracting artifact entry: /home/runner/work/fleet/fleet/main-mysql8.0.44-status/status
123:  Artifact download completed successfully.
124:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-core-mysql8.0.44-status/status
125:  Artifact download completed successfully.
126:  Extracting artifact entry: /home/runner/work/fleet/fleet/service-mysql8.0.44-status/status
127:  Artifact download completed successfully.
128:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-mdm-mysql8.0.44-status/status
129:  Artifact download completed successfully.
130:  Extracting artifact entry: /home/runner/work/fleet/fleet/fast-status/status
131:  Artifact download completed successfully.
132:  Total of 10 artifact(s) downloaded
133:  Download artifact has finished successfully
134:  ##[group]Run failed_tests=""
135:  �[36;1mfailed_tests=""�[0m
136:  �[36;1mstatus_count=0�[0m
137:  �[36;1m# Find all status files (they are in directories like 'fleetctl-mysql8.0.44-status/status')�[0m
138:  �[36;1mfor status_file in $(find ./ -type f -name 'status'); do�[0m
139:  �[36;1m  status_count=$((status_count + 1))�[0m
140:  �[36;1m  # Extract test name from parent directory (e.g., 'fleetctl-mysql8.0.44-status')�[0m
141:  �[36;1m  test_dir=$(basename $(dirname "$status_file"))�[0m
142:  �[36;1m  # Remove '-status' suffix to get the test name�[0m
143:  �[36;1m  test_name="${test_dir%-status}"�[0m
144:  �[36;1m  status_content=$(cat "$status_file")�[0m
145:  �[36;1m  echo "Processing: $status_file (Test: $test_name) with status content: $status_content"�[0m
146:  �[36;1m  if grep -q "fail" "$status_file"; then�[0m
147:  �[36;1m    echo "  ❌ Test failed: $test_name"�[0m
148:  �[36;1m    failed_tests="${failed_tests}${test_name}, "�[0m
149:  �[36;1m  else�[0m
150:  �[36;1m    echo "  ✅ Test passed: $test_name"�[0m
151:  �[36;1m  fi�[0m
152:  �[36;1mdone�[0m
153:  �[36;1mif [[ $status_count -eq 0 ]]; then�[0m
154:  �[36;1m  echo "❌ ERROR: No status files found! This indicates a workflow issue."�[0m
155:  �[36;1m  exit 1�[0m
156:  �[36;1mfi�[0m
157:  �[36;1mif [[ -n "$failed_tests" ]]; then�[0m
158:  �[36;1m  echo "❌ One or more test jobs failed: ${failed_tests%, }"�[0m
159:  �[36;1m  exit 1�[0m
160:  �[36;1mfi�[0m
161:  �[36;1mecho "✅ All test jobs succeeded."�[0m
162:  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
163:  ##[endgroup]
164:  Processing: ./integration-core-mysql8.0.44-status/status (Test: integration-core-mysql8.0.44) with status content: success
165:  ✅ Test passed: integration-core-mysql8.0.44
166:  Processing: ./vuln-mysql8.0.44-status/status (Test: vuln-mysql8.0.44) with status content: fail
167:  ❌ Test failed: vuln-mysql8.0.44
168:  Processing: ./service-mysql8.0.44-status/status (Test: service-mysql8.0.44) with status content: success
169:  ✅ Test passed: service-mysql8.0.44
170:  Processing: ./main-mysql8.0.44-status/status (Test: main-mysql8.0.44) with status content: success
171:  ✅ Test passed: main-mysql8.0.44
172:  Processing: ./fleetctl-mysql8.0.44-status/status (Test: fleetctl-mysql8.0.44) with status content: success
173:  ✅ Test passed: fleetctl-mysql8.0.44
174:  Processing: ./integration-enterprise-mysql8.0.44-status/status (Test: integration-enterprise-mysql8.0.44) with status content: success
175:  ✅ Test passed: integration-enterprise-mysql8.0.44
176:  Processing: ./fast-status/status (Test: fast) with status content: success
177:  ✅ Test passed: fast
178:  Processing: ./mysql-mysql8.0.44-status/status (Test: mysql-mysql8.0.44) with status content: success
179:  ✅ Test passed: mysql-mysql8.0.44
180:  Processing: ./integration-mdm-mysql8.0.44-status/status (Test: integration-mdm-mysql8.0.44) with status content: success
181:  ✅ Test passed: integration-mdm-mysql8.0.44
182:  Processing: ./scripts-status/status (Test: scripts) with status content: success
183:  ✅ Test passed: scripts
184:  ❌ One or more test jobs failed: vuln-mysql8.0.44
185:  ##[error]Process completed with exit code 1.
186:  Post job cleanup.

@lucasmrod
lucasmrod merged commit 441e31c into main Jun 3, 2026
30 of 32 checks passed
@lucasmrod
lucasmrod deleted the move-targets-and-secret-variables branch June 3, 2026 18:07
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.

Audit/resolve unneccessary fleetctl transitive dependencies

3 participants