Skip to content

feat: Determine default metro from profile#224

Draft
jedevc wants to merge 1 commit intostagingfrom
jedevc/default-metro
Draft

feat: Determine default metro from profile#224
jedevc wants to merge 1 commit intostagingfrom
jedevc/default-metro

Conversation

@jedevc
Copy link
Copy Markdown
Member

@jedevc jedevc commented Mar 23, 2026

So it needs to be manually specified less on create.

The best mechanism for doing with was allowing context.Context on the Fields calls.

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 updates the resource field-schema pipeline to be context-aware and uses the active config profile to infer a default metro (so users need to manually specify a metro less often during create/run flows).

Changes:

  • Extend resource.Resource.Fields to accept context.Context and update call sites/implementations accordingly.
  • Add Profile.DefaultMetro + GetDefaultMetro() and use it to default MetroName (and run --metro) from the current profile.
  • Adjust patch/visual-edit behavior to better preserve defaults during create flows.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/gendocs/mdx.go Updates doc generation to call Fields with a context (currently uses context.Background()).
tools/gendocs/man.go Updates manpage generation to call Fields with a context.
internal/resource/value/compare.go Adds value.IsZero helper for zero-value detection.
internal/resource/tui/panel_list.go Threads panel context into Fields calls.
internal/resource/tui/panel_detail.go Threads panel context into Fields calls.
internal/resource/testing/resource.go Updates test resource to the new Fields(ctx) signature.
internal/resource/sandbox.go Passes caller context into Fields when adding to sandbox.
internal/resource/resource.go Changes Resource.Fields interface to Fields(ctx context.Context).
internal/resource/patch/visual_test.go Updates tests for the new Fields(ctx) signature.
internal/resource/patch/visual.go Changes create/edit visual patch retention rules (defaults vs removals).
internal/resource/patch/patch.go Changes patch generation to preserve non-zero defaults (needs scoping to create).
internal/resource/cmd/sort.go Passes command context into Fields for sorting/validation.
internal/resource/cmd/resolve.go Passes command context into Fields during resolution.
internal/resource/cmd/printers.go Passes command context into Fields for all output formats.
internal/resource/cmd/cmd_test.go Updates tests to pass context into Fields.
internal/resource/cmd/cmd.go Uses Fields(ctx) and moves required-field validation before dry-run printing.
internal/config/profile.go Adds DefaultMetro and GetDefaultMetro() helper.
internal/cmd/volumes.go Defaults MetroName from current profile during field generation.
internal/cmd/services.go Defaults MetroName from current profile during field generation.
internal/cmd/run.go Makes --metro optional and falls back to profile default when absent; uses Fields(ctx).
internal/cmd/profile.go Updates to Fields(ctx) signature.
internal/cmd/metros.go Updates to Fields(ctx) signature.
internal/cmd/instances.go Defaults MetroName from current profile during field generation.
internal/cmd/images.go Updates to Fields(ctx) signature.
internal/cmd/certificates.go Defaults MetroName from current profile during field generation.
internal/cmd/any.go Updates to Fields(ctx) signature and threads ctx to underlying resource.

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

} else {
setForbiddenFields[keyStr] = struct{}{}
}
} else if original.Set != nil && !value.IsZero(original.Set) {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

In PatchedFields this new branch preserves non-zero original.Set even when the user did not specify a --set for the field. Because this code runs in both create and edit modes, edit operations will now generate patches for every editable field that currently has a non-zero value, causing large/no-op patch sets and potentially triggering unintended update calls. Restrict this default-preservation behavior to create mode only (e.g., guard with spec.Create) so edit mode only produces patches for explicitly requested fields.

Suggested change
} else if original.Set != nil && !value.IsZero(original.Set) {
} else if spec.Create && original.Set != nil && !value.IsZero(original.Set) {

Copilot uses AI. Check for mistakes.
if target, ok := node.Target.Interface().(cmd.ResourceCmdInterface); ok {
src := target.Underlying()
fields, err := src.Fields()
fields, err := src.Fields(context.Background())
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

generateMarkdown already receives a ctx, but this call uses context.Background(), which drops cancellation and any values attached to the caller context. Pass the provided ctx through to Fields so any context-aware field generation (e.g., lazy loading / profile-derived defaults) behaves consistently during doc generation.

Suggested change
fields, err := src.Fields(context.Background())
fields, err := src.Fields(ctx)

Copilot uses AI. Check for mistakes.
@jedevc jedevc force-pushed the jedevc/default-metro branch from 8d06de5 to 67ca717 Compare March 23, 2026 17:22
So it needs to be manually specified *less* on create.

Signed-off-by: Justin Chadwell <justin@unikraft.com>
@jedevc jedevc force-pushed the jedevc/default-metro branch from 67ca717 to 5699bc1 Compare April 1, 2026 17:17
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.

2 participants