Skip to content
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

feat: add WSL2 driver #1721

Merged
merged 1 commit into from
Sep 7, 2023
Merged

feat: add WSL2 driver #1721

merged 1 commit into from
Sep 7, 2023

Conversation

pendo324
Copy link
Contributor

@pendo324 pendo324 commented Aug 8, 2023

This PR users WSL2 to add a new VM Driver for Windows. This addresses the longstanding GitHub issue asking for Windows support (#391).

The traditional thinking (as seen in #909) is to make QEMU work on Windows, and the addition of a WSL2 driver should not inhibit that effort, just provide another option (I'd also like to see a direct HyperV option 👀 ).

Considerations:

  • The implementation in this PR currently does not forward the VM's SSH address to 127.0.0.1:<Instance.SSHLocalPort>, although this is possible through the use of netsh (I couldn't get ssh port forwarding to work). Currently, the PR just uses the WSL2 instance's IP address and port 22. I can add some netsh calling code to get this working relatively easily, I just wanted to know if that's required
  • The implementation requires an ssh binary on Windows, which isn't common. My recommendation is to have users install Git for Windows (specifically the MinGit release), which comes with some other helpful utilities like cygpath. Bundling this with Lima or just requiring users to run winget install -e --id Git.MinGit (winget is now built into Windows) and adding it to path are both possible. The version of OpenSSH installable as a Windows optional feature is pretty old. Open to suggestions incase I missed something.
  • The implementation uses WSL2's built-in network sharing and ssh forwarding of ports. It should technically be possible to use gvisor or similar, but I think that can be future work
  • The implementation keeps the WSL2 instance running until stopped by executing an extremely long sleep command. Open to suggestions here, as I'm sure there are better ways to do this
  • There might be some final debug code left in this diff. I will remove it in revisions over the coming days
  • There are a lot of tests left to be added, which I'll be working in the coming days

cmd/limactl/delete.go Outdated Show resolved Hide resolved
pkg/store/instance.go Outdated Show resolved Hide resolved
pkg/ioutilx/ioutilx.go Outdated Show resolved Hide resolved
@afbjorklund
Copy link
Member

@pendo324 : thank you for your contribution, it would be have been good to open an issue for discussion about the feature itself and keep the PR for the implementation - but that can be done afterwards too, and reference this PR

Running Lima in a container is slightly different from all the other drivers, so it might need some thought (Lima itself has some similaries to WSL2). I agree that a more traditional HyperV driver would also be a nice addition, like "VZ"...

@@ -53,9 +55,16 @@ func deleteInstance(inst *store.Instance, force bool) error {

stopInstanceForcibly(inst)

if inst.VMType == limayaml.WSL {
if _, err := executil.RunUTF16leCommand([]string{"wsl", "--unregister", inst.DistroName}); err != nil {
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 limit it to ASCII?

@pendo324
Copy link
Contributor Author

@pendo324 : thank you for your contribution, it would be have been good to open an issue for discussion about the feature itself and keep the PR for the implementation - but that can be done afterwards too, and reference this PR

Running Lima in a container is slightly different from all the other drivers, so it might need some thought (Lima itself has some similaries to WSL2). I agree that a more traditional HyperV driver would also be a nice addition, like "VZ"...

I'll create an issue to track Windows support in general, and weigh the different options (WSL2, HyperV, qemu, etc.) as I do think there are reasons you might want to use one over the other. I wanted to come to the project with some code instead of just an issue, but it ballooned into a lot of code before I knew it 😅

examples/default.yaml Outdated Show resolved Hide resolved
@pendo324
Copy link
Contributor Author

Addressed comments and rebased. Also added documentation. Would be good to merge #1726 first since it's just extracted from @afbjorklund PR. I can just squash it into this PR if that's preferable though.

@jandubois
Copy link
Member

I guess the most common reason to prefer WSL2 over bare Hyper-V would be to share files using 9p?

Another one is that WSL2 is supported in Windows Home whereas Hyper-V requires at least Windows Pro. This is purely a licensing issue as WSL2 is running on top of Hyper-V.

@pendo324
Copy link
Contributor Author

Not sure why the tests are failing, but it doesn't seem related. Should I keep retrying @AkihiroSuda?

@AkihiroSuda
Copy link
Member

Not sure why the tests are failing, but it doesn't seem related. Should I keep retrying @AkihiroSuda?

CI for Colima seems consistently failing after restarting several times. Maybe a regression in this PR?

@pendo324
Copy link
Contributor Author

Not sure why the tests are failing, but it doesn't seem related. Should I keep retrying @AkihiroSuda?

CI for Colima seems consistently failing after restarting several times. Maybe a regression in this PR?

Found the bug (typo) and fixed it (tests passed locally). Should be good to go after CI passes

docs/vmtype.md Outdated
> **Warning**
> "wsl2" mode is experimental

| :zap: Requirement | Lima >= 0.14, macOS >= 13.0 |
Copy link
Member

Choose a reason for hiding this comment

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

Seems a copy paste error

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, fixed in latest revision

@AkihiroSuda
Copy link
Member

Thanks, almost looks good, but needs rebase

@AkihiroSuda AkihiroSuda added this to the v0.18.0 milestone Sep 3, 2023
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
@pendo324
Copy link
Contributor Author

pendo324 commented Sep 5, 2023

Thanks, almost looks good, but needs rebase

Thanks. Just rebased and addressed your new comment

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

@pendo324
Copy link
Contributor Author

pendo324 commented Sep 5, 2023

Looks like the tests failed/timed out on TestGetPorts/nodePort_serivce. Trying to repro locally

@pendo324
Copy link
Contributor Author

pendo324 commented Sep 6, 2023

Couldn't repro test error locally:

$ go test -timeout 30s -v -run ^TestGetPorts github.com/lima-vm/lima/pkg/guestagent/kubernetesservice

=== RUN   TestGetPorts
=== RUN   TestGetPorts/nodePort_serivce
=== RUN   TestGetPorts/loadBalancer_service
=== RUN   TestGetPorts/clusterIP_service
--- PASS: TestGetPorts (0.00s)
    --- PASS: TestGetPorts/nodePort_serivce (0.00s)
    --- PASS: TestGetPorts/loadBalancer_service (0.00s)
    --- PASS: TestGetPorts/clusterIP_service (0.00s)
PASS
ok      github.com/lima-vm/lima/pkg/guestagent/kubernetesservice        0.440s

Is it possible to re-run the step?

@AkihiroSuda
Copy link
Member

AkihiroSuda commented Sep 7, 2023

Restarted CI, all green

@AkihiroSuda AkihiroSuda merged commit deed2d6 into lima-vm:master Sep 7, 2023
25 checks passed
@AkihiroSuda AkihiroSuda mentioned this pull request Sep 7, 2023
@AkihiroSuda
Copy link
Member

PTAL:

@AkihiroSuda AkihiroSuda mentioned this pull request Sep 27, 2023
@Anutrix Anutrix mentioned this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants