Skip to content

[WIP]: Create a Plugin System for Lima #3573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

unsuman
Copy link
Contributor

@unsuman unsuman commented May 23, 2025

Important

This PR is only for preview purposes and not meant to be merged. Later, the commits can be cherry-picked and raised as separate small PRs.

This PR creates a Plugin System for drivers which can be embedded in the main binary or built as separate binaries, which then communicate with the main binary using gRPC. This work is done as part of my GSoC '25 task.

@AkihiroSuda AkihiroSuda added the gsoc/2025 Google Summer of Code 2025 label May 23, 2025
@unsuman unsuman force-pushed the feature/driver-plugin-system branch from 77877e0 to 7a082d2 Compare May 25, 2025 11:21
@@ -54,6 +56,9 @@ $ limactl create --set='.cpus = 2 | .memory = "2GiB"'
To see the template list:
$ limactl create --list-templates

To see the drivers list:
$ limactl create --list-drivers
Copy link
Member

Choose a reason for hiding this comment

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

The example currently just focuses on templates, not on drivers.

@@ -16,7 +16,7 @@ import (
"github.com/docker/go-units"
"github.com/lima-vm/go-qcow2reader"
"github.com/lima-vm/lima/pkg/nativeimgutil"
"github.com/lima-vm/lima/pkg/qemu/imgutil"
"github.com/lima-vm/lima/pkg/qemuimgutil"
Copy link
Member

Choose a reason for hiding this comment

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

Eventually this should follow:

Not an urgent topic though

// SPDX-FileCopyrightText: Copyright The Lima Authors
// SPDX-License-Identifier: Apache-2.0

package builtins
Copy link
Member

Choose a reason for hiding this comment

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

builitins should be in cmd/limactl/main*.go

import (
// Import all built-in drivers to register them in the registry.
_ "github.com/lima-vm/lima/pkg/driver/qemu"
_ "github.com/lima-vm/lima/pkg/driver/vz"
Copy link
Member

Choose a reason for hiding this comment

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

should be in main_darwin.go

// Import all built-in drivers to register them in the registry.
_ "github.com/lima-vm/lima/pkg/driver/qemu"
_ "github.com/lima-vm/lima/pkg/driver/vz"
_ "github.com/lima-vm/lima/pkg/driver/wsl2"
Copy link
Member

Choose a reason for hiding this comment

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

should be in main_windows.go


DeleteSnapshot(_ context.Context, tag string) error
// Snapshot defines operations for managing snapshots.
type Snapshot interface {
Copy link
Member

@AkihiroSuda AkihiroSuda May 26, 2025

Choose a reason for hiding this comment

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

This represents a manager of snapshots, not a snapshot itself.

So it should be named like SnapshotManager or Snapshotter?
The latter one might be confusing, as it conflicts with the terminology of containerd, though.

}

func (l *LimaVzDriver) ListSnapshots(_ context.Context) (string, error) {
return "", errors.New("unimplemented")
Copy link
Member

Choose a reason for hiding this comment

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

The common ErrImplemented should be defined so that it can be compared with errors.Is

@@ -0,0 +1,118 @@
//go:build !darwin || no_vz
Copy link
Member

Choose a reason for hiding this comment

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

The package shouldn't be compiled at all on non-Darwin

@unsuman unsuman force-pushed the feature/driver-plugin-system branch from 3f1de89 to e53a368 Compare May 26, 2025 13:34
unsuman added 16 commits May 27, 2025 15:24
Signed-off-by: Ansuman Sahoo <[email protected]>
…plugin related functions

Signed-off-by: Ansuman Sahoo <[email protected]>
@unsuman unsuman force-pushed the feature/driver-plugin-system branch from e53a368 to 4630452 Compare May 27, 2025 10:28

message Empty {}

message InstanceConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Can we just pass the byte array of YAML (or JSON), so that we do not need to sync the YAML struct with this proto definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure we can do that!


rpc GetVSockPort(google.protobuf.Empty) returns (GetVSockPortResponse);
rpc GetVirtioPort(google.protobuf.Empty) returns (GetVirtioPortResponse);
}
Copy link
Member

Choose a reason for hiding this comment

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

CanRunGUI, Name, GetVSockPort, and GetVirtioPort could be consolidated into a single Info() rpc call.

Not urgent.

Copy link
Contributor Author

@unsuman unsuman Jun 2, 2025

Choose a reason for hiding this comment

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

@AkihiroSuda Should I also consolidate these functions in the driver.Driver interface, in order to maintain consistency?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

func (d *DriverClient) Initialize(ctx context.Context) error {
d.logger.Debug("Initializing driver instance")

connCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

timeout should be specified in the caller

for {
n, err := conn.Read(buf)
if err != nil {
if err == io.EOF {
Copy link
Member

Choose a reason for hiding this comment

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

errors.Is is more robust

@unsuman unsuman force-pushed the feature/driver-plugin-system branch from 605e45e to 2a82bf3 Compare June 5, 2025 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc/2025 Google Summer of Code 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants