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

fix: guestagent port forwarding behavior on wsl2 #2213

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading