Skip to content

Commit

Permalink
Merge pull request #2009 from AkihiroSuda/dev
Browse files Browse the repository at this point in the history
hostagent: avoid requiring `fuser` and `ss` in the guest ; CI: update colima (v0.5.5→v0.6.5)
  • Loading branch information
AkihiroSuda authored Nov 24, 2023
2 parents 70d0177 + d1e52c9 commit f3b4dec
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 50 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ jobs:
timeout-minutes: 120
strategy:
matrix:
colima-version: ["v0.5.5"]
colima-version: ["v0.6.5"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
# fetch-depth is set to 0 to let `limactl --version` print semver-ish version
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-go@v4
with:
go-version: 1.20.x
Expand Down
49 changes: 36 additions & 13 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type HostAgent struct {

clientMu sync.RWMutex
client guestagentclient.GuestAgentClient

guestAgentAliveCh chan struct{} // closed on establishing the connection
guestAgentAliveChOnce sync.Once
}

type options struct {
Expand Down Expand Up @@ -160,19 +163,20 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
})

a := &HostAgent{
y: y,
sshLocalPort: sshLocalPort,
udpDNSLocalPort: udpDNSLocalPort,
tcpDNSLocalPort: tcpDNSLocalPort,
instDir: inst.Dir,
instName: instName,
instSSHAddress: inst.SSHAddress,
sshConfig: sshConfig,
portForwarder: newPortForwarder(sshConfig, sshLocalPort, rules, inst.VMType),
driver: limaDriver,
sigintCh: sigintCh,
eventEnc: json.NewEncoder(stdout),
vSockPort: vSockPort,
y: y,
sshLocalPort: sshLocalPort,
udpDNSLocalPort: udpDNSLocalPort,
tcpDNSLocalPort: tcpDNSLocalPort,
instDir: inst.Dir,
instName: instName,
instSSHAddress: inst.SSHAddress,
sshConfig: sshConfig,
portForwarder: newPortForwarder(sshConfig, sshLocalPort, rules, inst.VMType),
driver: limaDriver,
sigintCh: sigintCh,
eventEnc: json.NewEncoder(stdout),
vSockPort: vSockPort,
guestAgentAliveCh: make(chan struct{}),
}
return a, nil
}
Expand Down Expand Up @@ -492,6 +496,21 @@ sudo chown -R "${USER}" /run/host-services`
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
errs = append(errs, err)
}
if !*a.y.Plain {
logrus.Info("Waiting for the guest agent to be running")
select {
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)
}
}
}
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
errs = append(errs, err)
}
Expand Down Expand Up @@ -605,6 +624,10 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestage
if err != nil {
return err
}
logrus.Info("Guest agent is running")
a.guestAgentAliveChOnce.Do(func() {
close(a.guestAgentAliveCh)
})

logrus.Debugf("guest agent info: %+v", info)

Expand Down
35 changes: 0 additions & 35 deletions pkg/hostagent/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/lima-vm/lima/pkg/limayaml"
"github.com/lima-vm/lima/pkg/store/filenames"
"github.com/lima-vm/sshocker/pkg/ssh"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -120,40 +119,6 @@ fi
debugHint: `Append "user_allow_other" to /etc/fuse.conf (/etc/fuse3.conf) in the guest`,
})
}
if a.vSockPort != 0 {
req = append(req, requirement{
description: "the guest agent to be running",
script: fmt.Sprintf(`#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until ss -a -n --vsock --listen | grep -q ':%d'; do sleep 3; done"; then
echo >&2 "lima-guestagent is not installed yet"
exit 1
fi
`, a.vSockPort),
debugHint: fmt.Sprintf(`The guest agent with vsockPort %d does not seem running.
Make sure that you are using an officially supported image.
Also see "/var/log/cloud-init-output.log" in the guest.
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
`, a.vSockPort),
})
} else {
req = append(req, requirement{
description: "the guest agent to be running",
script: fmt.Sprintf(`#!/bin/bash
set -eux -o pipefail
sock="/dev/virtio-ports/%s"
if ! timeout 30s bash -c "until sudo fuser \"${sock}\" || sudo lsof \"${sock}\"; do sleep 3; done"; then
echo >&2 "lima-guestagent is not installed yet"
exit 1
fi
`, filenames.VirtioPort),
debugHint: fmt.Sprintf(`The guest agent with serialport /dev/virtio-ports/%s does not seem running.
Make sure that you are using an officially supported image.
Also see "/var/log/cloud-init-output.log" in the guest.
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
`, filenames.VirtioPort),
})
}
return req
}

Expand Down

0 comments on commit f3b4dec

Please sign in to comment.