Skip to content

Conversation

unsuman
Copy link
Contributor

@unsuman unsuman commented Aug 25, 2025

Note

This is the last PR of the three PRs, which depends on #3901. Merging all will close #3769.

Key Changes

  • Changes to the .proto files to incorporate with the driver interface.
  • Since FillConfig() and AcceptConfig() are both pre-configured driver operations, I have implemented stdio piping transport using json between limactl and the driver binary. The driver binary can know that limactl is calling for a pre-grpc action by a boolean flag --pre-driver-action.

One more thing, we tend to inspect instances a lot throughout the codebase(even for simply listing Lima instances through limactl ls) so I have also implemented the same stdio transport mechanism for InspectStatus() so that it saves us time and resource but it is an add-on, let me know if we don't need this then I can revert the changes!

@AkihiroSuda AkihiroSuda added gsoc/2025 Google Summer of Code 2025 area/vmdrivers VM driver infrastructure labels Aug 25, 2025
@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Aug 25, 2025
@AkihiroSuda
Copy link
Member

Please rebase

// To be used as an external driver for Lima.
func main() {
server.Serve(context.Background(), vz.New())
server.Serve(vz.New())
Copy link
Member

Choose a reason for hiding this comment

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

?


var payload []byte
if err := decoder.Decode(&payload); err != nil {
fmt.Fprintf(os.Stderr, "Error encoding response: %v\n", err)
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use logrus?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we change this to logrus, it will not be clean. For e.g:

➜  lima2 git:(refactor/support-external-drivers) ✗ ./_output/bin/limactl edit default2 --mount-type virtiofs
FATA[0000] failed to resolve vm for "/Users/ansumansahoo/.lima/default2/lima.yaml": external driver stderr:
 time="2025-08-27T01:51:33+05:30" level=error msg="Failed to accept config: config not supported by the QEMU driver: 
 field `mountType` must be \"reverse-sshfs\" or \"9p\" for QEMU driver on non-Linux, got \"virtiofs\"" 

Using fmt.Fprintf results in a clean error:

➜  lima2 git:(refactor/support-external-drivers) ✗ ./_output/bin/limactl edit default2 --mount-type virtiofs
FATA[0000] failed to resolve vm for "/Users/ansumansahoo/.lima/default2/lima.yaml": 
external driver stderr: Failed to accept config: config not supported by the QEMU driver: 
field `mountType` must be "reverse-sshfs" or "9p" for QEMU driver on non-Linux, got "virtiofs" 

And since it will be never be stored in the driver.stderr.log

}

func handlePreConfiguredDriverAction(y *limatype.LimaYAML, extDriverPath, filePath string) error {
cmd := exec.CommandContext(context.Background(), extDriverPath, "--pre-driver-action")
Copy link
Member

Choose a reason for hiding this comment

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

ctx should be passed from the caller

}

func handleInspectStatusAction(inst *limatype.Instance, extDriverPath string) (string, error) {
cmd := exec.CommandContext(context.Background(), extDriverPath, "--inspect-status")
Copy link
Member

Choose a reason for hiding this comment

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

Same

VirtioPort string `json:"virtioPort"`
InstanceDir string `json:"instanceDir,omitempty"`
DriverName string `json:"driverName"`
CanRunGUI bool `json:"canRunGui,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved to DriverFeatures

@unsuman unsuman force-pushed the refactor/support-external-drivers branch from 7e99f45 to 3cf0d16 Compare August 26, 2025 06:26
@unsuman
Copy link
Contributor Author

unsuman commented Aug 26, 2025

I will open the PR after some time, working on making the pre-validation action error handling better.

@unsuman unsuman force-pushed the refactor/support-external-drivers branch 4 times, most recently from 8c27373 to 3990779 Compare August 26, 2025 20:52
@unsuman unsuman force-pushed the refactor/support-external-drivers branch from 3990779 to d4dc0a5 Compare August 26, 2025 21:01
@unsuman unsuman marked this pull request as ready for review August 26, 2025 21:55
Copy link
Member

Choose a reason for hiding this comment

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

Next time please split a commit for this

type DriverFeatures struct {
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
SkipSocketForwarding bool `json:"skipSocketForwarding"`
DriverName string `json:"driverName"`
Copy link
Member

Choose a reason for hiding this comment

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

Name does not seem to be a feature

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit f7861fb into lima-vm:master Aug 27, 2025
88 of 90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/vmdrivers VM driver infrastructure gsoc/2025 Google Summer of Code 2025

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Lima Config and External Drivers

2 participants