Skip to content

refac: Update Satellite to use generated GC Client - #615

Open
vg006 wants to merge 3 commits into
container-registry:mainfrom
vg006:refac/sat
Open

refac: Update Satellite to use generated GC Client#615
vg006 wants to merge 3 commits into
container-registry:mainfrom
vg006:refac/sat

Conversation

@vg006

@vg006 vg006 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates the satellite package to use the generated Ground Control package in pkg/groundcontrol to communicate with it. This will enable type-safe and type-aware request-response model for Satellite and GC.

Review in cubic

Summary by CodeRabbit

  • Improvements
    • Improved satellite registration and status reporting with more reliable, structured communication.
    • Added clearer handling for authorization, server, and unexpected response errors.
    • Preserved diagnostic details when registration or reporting fails.
    • Enhanced secure connection support, including SPIFFE, TLS, and basic authentication.
    • Increased supported ranges for memory, storage, and synchronization-duration metrics.
    • Added validation to reject out-of-range metrics and prevent invalid registration data from overwriting existing configuration.

vg006 added 2 commits August 11, 2026 23:09
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b141931-2fb6-42ef-84d2-c198f609a2b7

📥 Commits

Reviewing files that changed from the base of the PR and between 3cb03c7 and 70679ef.

📒 Files selected for processing (7)
  • internal/groundcontrol/server/cached_images_test.go
  • internal/groundcontrol/server/helpers.go
  • internal/groundcontrol/server/satellite_handlers.go
  • internal/satellite/state/registration_process.go
  • internal/satellite/state/report_test.go
  • internal/satellite/state/reporting_process.go
  • internal/satellite/state/reporting_process_test.go
💤 Files with no reviewable changes (1)
  • internal/groundcontrol/server/helpers.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/satellite/state/report_test.go
  • internal/satellite/state/registration_process.go
  • internal/satellite/state/reporting_process.go

📝 Walkthrough

Walkthrough

The PR updates Ground Control status metric types, replaces manual registration and reporting HTTP calls with generated client operations, standardizes typed response errors, and reuses generated cached-image and status request models.

Changes

Ground Control client migration

Layer / File(s) Summary
Ground Control API contracts and metric validation
spec/ground-control/openapi.yaml, pkg/groundcontrol/client.gen.go, internal/groundcontrol/server/...
Status metrics now use uint64 request fields. The server rejects values above math.MaxInt64 and converts accepted values to nullable database integers.
Typed registration flows
internal/satellite/state/helpers.go, internal/satellite/state/registration_process.go, internal/satellite/state/spiffe_registration.go, internal/satellite/state/registration_process_test.go
Token-based and SPIFFE registration now use generated Ground Control operations. Success responses map to StateConfig. Tests cover typed errors, unknown response bodies, TLS handling, and state preservation.
Typed status reporting
internal/satellite/state/catalog.go, internal/satellite/state/report.go, internal/satellite/state/reporting_process.go, internal/satellite/state/report_test.go, internal/satellite/state/reporting_process_test.go
Status reports now use generated request and cached-image types. Sync calls support typed responses, Basic Auth, HTTPS validation, and structured error handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

Possibly related PRs

Suggested labels: chore

Sequence Diagram(s)

sequenceDiagram
  participant Satellite
  participant GroundControlClient
  participant GroundControlAPI
  Satellite->>GroundControlClient: ZTRRequest or SatelliteStatusRequest
  GroundControlClient->>GroundControlAPI: ZtrWithResponse, SpiffeZtrWithResponse, or SyncSatelliteWithResponse
  GroundControlAPI-->>GroundControlClient: typed success or error response
  GroundControlClient-->>Satellite: StateConfig, status result, or structured error
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% 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 title clearly summarizes the main change: updating Satellite to use the generated Ground Control client.
Description check ✅ Passed The description includes the required issue reference and a clear summary; the optional additional-context section is not needed.
Linked Issues check ✅ Passed The changes satisfy [#609] by replacing manual Ground Control calls with generated clients, typed models, validated conversions, and typed response handling.
Out of Scope Changes check ✅ Passed The changes remain within [#609], including generated model updates, numeric validation, client migration, response handling, and related tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@gitar-bot

gitar-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

@vg006 vg006 changed the title Refac/sat refac: Update Satellite to use generated GC Client Aug 11, 2026
@codacy-production

codacy-production Bot commented Aug 11, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 medium

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Complexity 1 medium

View in Codacy

🟢 Metrics 22 complexity · 13 duplication

Metric Results
Complexity 22
Duplication 13

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
spec/ground-control/openapi.yaml (1)

2318-2322: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Add a non-negative constraint for last_sync_duration_ms.

The schema accepts negative integers. The generated Go field is uint64. Add minimum: 0 so OpenAPI clients and validators use the same contract.

🤖 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 `@spec/ground-control/openapi.yaml` around lines 2318 - 2322, Update the
last_sync_duration_ms schema property to add a minimum value of 0, aligning
OpenAPI validation with its uint64 x-go-type and preventing negative durations.
🤖 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 `@internal/groundcontrol/server/helpers.go`:
- Around line 366-368: Update the request handling flow after DecodeRequestBody
and before artifact or status inserts to reject any of the three uint64 fields
exceeding math.MaxInt64. Return the existing appropriate validation error
response without converting or persisting invalid values, while keeping
toNullUInt64 unchanged for in-range values.

In `@internal/satellite/state/registration_process.go`:
- Around line 244-255: Update the TLS configuration branch in the registration
client to also execute when tlsCfg.SkipVerify is true, even if CertFile and
CAFile are empty. Preserve the existing satTLS.LoadClientTLSConfig call and
validation behavior, including ValidateAndEnforceDefaults handling incomplete
certificate/key pairs.

In `@internal/satellite/state/report_test.go`:
- Around line 23-25: Update TestCollectStatusReportParams_UnreachableRegistry to
use int32(0) as the expected value in the assertion comparing against
req.ImageCount, preserving the existing unreachable-registry test behavior.

In `@internal/satellite/state/reporting_process.go`:
- Around line 148-159: Move the UseUnsecure/groundControlURL HTTPS validation
from the non-SPIFFE else branch to execute before the s.spiffeClient branch.
When UseUnsecure is false, reject any Ground Control URL that does not use HTTPS
before selecting either the SPIFFE or TLS client, while preserving the existing
client setup and error message.

---

Outside diff comments:
In `@spec/ground-control/openapi.yaml`:
- Around line 2318-2322: Update the last_sync_duration_ms schema property to add
a minimum value of 0, aligning OpenAPI validation with its uint64 x-go-type and
preventing negative durations.
🪄 Autofix

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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2711430-7c04-4106-b026-1884e762dd00

📥 Commits

Reviewing files that changed from the base of the PR and between 341cb42 and 3cb03c7.

📒 Files selected for processing (14)
  • internal/groundcontrol/server/helpers.go
  • internal/groundcontrol/server/satellite_handlers.go
  • internal/groundcontrol/server/server.gen.go
  • internal/satellite/state/catalog.go
  • internal/satellite/state/helpers.go
  • internal/satellite/state/registration_process.go
  • internal/satellite/state/registration_process_test.go
  • internal/satellite/state/report.go
  • internal/satellite/state/report_test.go
  • internal/satellite/state/reporting_process.go
  • internal/satellite/state/reporting_process_test.go
  • internal/satellite/state/spiffe_registration.go
  • pkg/groundcontrol/client.gen.go
  • spec/ground-control/openapi.yaml

Comment thread internal/groundcontrol/server/helpers.go
Comment thread internal/satellite/state/registration_process.go Outdated
Comment thread internal/satellite/state/report_test.go
Comment thread internal/satellite/state/reporting_process.go Outdated

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 14 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/groundcontrol/client.gen.go">

<violation number="1" location="pkg/groundcontrol/client.gen.go:423">
P2: Status reports can persist corrupted negative byte/duration metrics when a value above `math.MaxInt64` is sent, because this model now accepts the full `uint64` range while Ground Control stores it in signed `BIGINT` fields. Keeping the request range within `int64` or rejecting oversized values before the `toNullUInt64` conversion would preserve the API and database contract.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread internal/satellite/state/report_test.go
CPUPercent float64 `json:"cpu_percent,omitempty,omitzero"`
ImageCount int32 `json:"image_count,omitempty,omitzero"`
LastSyncDurationMs int64 `json:"last_sync_duration_ms,omitempty,omitzero"`
LastSyncDurationMs uint64 `json:"last_sync_duration_ms,omitempty,omitzero"`

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.

P2: Status reports can persist corrupted negative byte/duration metrics when a value above math.MaxInt64 is sent, because this model now accepts the full uint64 range while Ground Control stores it in signed BIGINT fields. Keeping the request range within int64 or rejecting oversized values before the toNullUInt64 conversion would preserve the API and database contract.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At pkg/groundcontrol/client.gen.go, line 423:

<comment>Status reports can persist corrupted negative byte/duration metrics when a value above `math.MaxInt64` is sent, because this model now accepts the full `uint64` range while Ground Control stores it in signed `BIGINT` fields. Keeping the request range within `int64` or rejecting oversized values before the `toNullUInt64` conversion would preserve the API and database contract.</comment>

<file context>
@@ -420,14 +420,14 @@ type SatelliteStatusRequest struct {
 	CPUPercent          float64             `json:"cpu_percent,omitempty,omitzero"`
 	ImageCount          int32               `json:"image_count,omitempty,omitzero"`
-	LastSyncDurationMs  int64               `json:"last_sync_duration_ms,omitempty,omitzero"`
+	LastSyncDurationMs  uint64              `json:"last_sync_duration_ms,omitempty,omitzero"`
 	LatestConfigDigest  string              `json:"latest_config_digest,omitempty,omitzero"`
 	LatestStateDigest   string              `json:"latest_state_digest,omitempty,omitzero"`
</file context>

Signed-off-by: vg006 <devvg006@gmail.com>
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.16949% with 47 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@341cb42). Learn more about missing BASE report.

Files with missing lines Patch % Lines
internal/satellite/state/spiffe_registration.go 0.00% 22 Missing ⚠️
internal/satellite/state/registration_process.go 51.61% 13 Missing and 2 partials ⚠️
internal/satellite/state/reporting_process.go 74.19% 7 Missing and 1 partial ⚠️
internal/satellite/state/catalog.go 85.71% 1 Missing ⚠️
internal/satellite/state/report.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #615   +/-   ##
=======================================
  Coverage        ?   20.75%           
=======================================
  Files           ?      131           
  Lines           ?    14131           
  Branches        ?        0           
=======================================
  Hits            ?     2933           
  Misses          ?    10924           
  Partials        ?      274           
Flag Coverage Δ
unittests 20.75% <60.16%> (?)

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

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Satellite to use generated GC Client

1 participant