Skip to content

Commit

Permalink
Merge pull request #2213 from pendo324/wsl2-guestagent-fixes
Browse files Browse the repository at this point in the history
fix: guestagent port forwarding behavior on wsl2
  • Loading branch information
jandubois authored Feb 17, 2024
2 parents e9105bd + a04e742 commit eb7b7e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
10 changes: 2 additions & 8 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,7 @@ sudo chown -R "${USER}" /run/host-services`
case <-a.guestAgentAliveCh:
// NOP
case <-time.After(time.Minute):
err := errors.New("guest agent does not seem to be running; port forwards will not work")
if *a.y.VMType == limayaml.WSL2 {
// geustagent is currently not available for WSL2: https://github.com/lima-vm/lima/issues/2025
logrus.Warn(err)
} else {
errs = append(errs, err)
}
errs = append(errs, errors.New("guest agent does not seem to be running; port forwards will not work"))
}
}
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
Expand Down Expand Up @@ -660,7 +654,7 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client *guestag
for _, f := range ev.Errors {
logrus.Warnf("received error from the guest: %q", f)
}
a.portForwarder.OnEvent(ctx, ev, a.instSSHAddress)
a.portForwarder.OnEvent(ctx, ev)
}

if err := client.Events(ctx, onEvent); err != nil {
Expand Down
18 changes: 4 additions & 14 deletions pkg/hostagent/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,8 @@ func hostAddress(rule limayaml.PortForward, guest *api.IPPort) string {
return host.HostString()
}

func (pf *portForwarder) forwardingAddresses(guest *api.IPPort, localUnixIP net.IP) (hostAddr, guestAddr string) {
func (pf *portForwarder) forwardingAddresses(guest *api.IPPort) (hostAddr, guestAddr string) {
guestIP := net.ParseIP(guest.Ip)
if pf.vmType == limayaml.WSL2 {
guestIP = localUnixIP
host := &api.IPPort{
Ip: guestIP.String(),
Port: guest.Port,
}
return host.String(), guest.HostString()
}
for _, rule := range pf.rules {
if rule.GuestSocket != "" {
continue
Expand Down Expand Up @@ -82,11 +74,9 @@ func (pf *portForwarder) forwardingAddresses(guest *api.IPPort, localUnixIP net.
return "", guest.HostString()
}

func (pf *portForwarder) OnEvent(ctx context.Context, ev *api.Event, instSSHAddress string) {
localUnixIP := net.ParseIP(instSSHAddress)

func (pf *portForwarder) OnEvent(ctx context.Context, ev *api.Event) {
for _, f := range ev.LocalPortsRemoved {
local, remote := pf.forwardingAddresses(f, localUnixIP)
local, remote := pf.forwardingAddresses(f)
if local == "" {
continue
}
Expand All @@ -96,7 +86,7 @@ func (pf *portForwarder) OnEvent(ctx context.Context, ev *api.Event, instSSHAddr
}
}
for _, f := range ev.LocalPortsAdded {
local, remote := pf.forwardingAddresses(f, localUnixIP)
local, remote := pf.forwardingAddresses(f)
if local == "" {
logrus.Infof("Not forwarding TCP %s", remote)
continue
Expand Down

0 comments on commit eb7b7e6

Please sign in to comment.