Conversation
There was a problem hiding this comment.
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.Fieldsto acceptcontext.Contextand update call sites/implementations accordingly. - Add
Profile.DefaultMetro+GetDefaultMetro()and use it to defaultMetroName(andrun --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.
internal/resource/patch/patch.go
Outdated
| } else { | ||
| setForbiddenFields[keyStr] = struct{}{} | ||
| } | ||
| } else if original.Set != nil && !value.IsZero(original.Set) { |
There was a problem hiding this comment.
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.
| } else if original.Set != nil && !value.IsZero(original.Set) { | |
| } else if spec.Create && original.Set != nil && !value.IsZero(original.Set) { |
tools/gendocs/mdx.go
Outdated
| if target, ok := node.Target.Interface().(cmd.ResourceCmdInterface); ok { | ||
| src := target.Underlying() | ||
| fields, err := src.Fields() | ||
| fields, err := src.Fields(context.Background()) |
There was a problem hiding this comment.
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.
| fields, err := src.Fields(context.Background()) | |
| fields, err := src.Fields(ctx) |
8d06de5 to
67ca717
Compare
So it needs to be manually specified *less* on create. Signed-off-by: Justin Chadwell <justin@unikraft.com>
67ca717 to
5699bc1
Compare
So it needs to be manually specified less on create.
The best mechanism for doing with was allowing
context.Contexton theFieldscalls.