Skip to content

fix: Better linking of resources#278

Merged
jedevc merged 2 commits intostagingfrom
jedevc/better-linking
Apr 28, 2026
Merged

fix: Better linking of resources#278
jedevc merged 2 commits intostagingfrom
jedevc/better-linking

Conversation

@jedevc
Copy link
Copy Markdown
Member

@jedevc jedevc commented Apr 16, 2026

We don't need all this super weird stuff where we have to manually iterate to create the fields. We can just do this automatically in FieldsFromStruct.

@jedevc jedevc force-pushed the jedevc/better-linking branch from d802a4a to 9e62f01 Compare April 22, 2026 15:54
Comment thread internal/resource/resource.go Outdated
@jedevc jedevc force-pushed the jedevc/better-linking branch 2 times, most recently from 6a8d7fe to 7043fff Compare April 22, 2026 16:10
Comment thread internal/resource/resource.go Outdated
We don't need all this super weird stuff where we have to manually
iterate to create the fields. We can just do this automatically in
FieldsFromStruct.

Signed-off-by: Justin Chadwell <justin@unikraft.com>
Copy link
Copy Markdown

Copilot AI left a comment

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 refactors resource linking so that links can be detected automatically during FieldsFromStruct processing, removing a lot of per-resource manual link wiring.

Changes:

  • Replace resource.Link (struct) with a resource.Link interface and update consumers (TUI, sandbox cleanup, JSON marshaling).
  • Enhance FieldsFromStruct to (a) flatten anonymous embedded structs and (b) detect Link implementations and bubble links appropriately.
  • Introduce generic link helper types in internal/cmd/link.go and migrate several resources (instances, services, volumes, templates, certificates) to use them; update/extend tests and golden outputs.

Reviewed changes

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

Show a summary per file
File Description
internal/types/image.go Adds Link() to ImageRef so image fields can auto-produce links.
internal/resource/value/format.go Avoids panics by handling nil / nil-pointer values before interface checks.
internal/resource/tui/panel_detail.go Switches TUI link tracking to resource.Link interface and resolves link targets via Link().
internal/resource/struct_test.go Adds coverage for anonymous embedded structs and link detection/bubbling behavior.
internal/resource/struct.go Refactors struct-to-fields conversion, adds centralized link detection, and flattens anonymous embeddings.
internal/resource/sandbox.go Updates sandbox link traversal to use Link() and derived key strings.
internal/resource/resource.go Replaces Link struct with Link interface and adds Field.MarshalJSON() to serialize links.
internal/cmd/volumes.go Migrates volume fields/refs to LinkName and embedded Link[Instance], removing manual link construction.
internal/cmd/volume_templates.go Migrates metro reference to LinkName and removes manual metro linking.
internal/cmd/services.go Migrates metro and nested refs (instances/certificates) to embedded Link[...], removing manual link construction.
internal/cmd/link.go Introduces generic Link[T] and LinkName[T] types implementing resource.Link.
internal/cmd/instances.go Migrates metro to LinkName and replaces manual link construction with auto-linking; retains hyperlink behavior.
internal/cmd/instance_templates.go Migrates metro to LinkName and removes manual link construction.
internal/cmd/certificates.go Migrates metro to LinkName and removes manual link construction.
cmd/unikraft/testdata/TestGolden/volumes/import/serve Golden output update reflecting field ordering changes.
cmd/unikraft/testdata/TestGolden/instances/volume-inline Adds golden case for inline volume create/inspect/delete.
cmd/unikraft/testdata/TestGolden/instances/volume Adds golden case for named volume attach flow.
cmd/unikraft/testdata/TestGolden/instances/help Golden output update reflecting field ordering changes.
cmd/unikraft/testdata/TestGolden/instances/connect Golden output update reflecting field ordering changes.
cmd/unikraft/testdata/TestGolden/instances/autostart Adds golden case for autostart create/inspect/delete.
cmd/unikraft/testdata/TestGolden/instances/add-domain Golden output update reflecting field ordering changes.
cmd/unikraft/instances_test.go Renames subtests for new/updated instance golden scenarios.

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

Comment thread internal/resource/resource.go Outdated
Copy link
Copy Markdown
Member

@craciunoiuc craciunoiuc left a comment

Choose a reason for hiding this comment

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

Good to go after the typo is fixed.

Reviewed-by: Cezar Craciunoiu cezar.craciunoiu@unikraft.com
Approved-by: Cezar Craciunoiu cezar.craciunoiu@unikraft.com

Signed-off-by: Justin Chadwell <justin@unikraft.com>
@jedevc jedevc force-pushed the jedevc/better-linking branch from 19b5b11 to 820865b Compare April 28, 2026 07:41
@jedevc jedevc merged commit d40b99d into staging Apr 28, 2026
9 checks passed
@jedevc jedevc deleted the jedevc/better-linking branch April 28, 2026 07:46
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.

4 participants