Skip to content

Commit f3b4dec

Browse files
authored
Merge pull request #2009 from AkihiroSuda/dev
hostagent: avoid requiring `fuser` and `ss` in the guest ; CI: update colima (v0.5.5→v0.6.5)
2 parents 70d0177 + d1e52c9 commit f3b4dec

File tree

3 files changed

+40
-50
lines changed

3 files changed

+40
-50
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,13 @@ jobs:
263263
timeout-minutes: 120
264264
strategy:
265265
matrix:
266-
colima-version: ["v0.5.5"]
266+
colima-version: ["v0.6.5"]
267267
steps:
268268
- uses: actions/checkout@v4
269269
with:
270-
fetch-depth: 1
270+
# fetch-depth is set to 0 to let `limactl --version` print semver-ish version
271+
fetch-depth: 0
272+
ref: ${{ github.event.pull_request.head.sha }}
271273
- uses: actions/setup-go@v4
272274
with:
273275
go-version: 1.20.x

pkg/hostagent/hostagent.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type HostAgent struct {
5757

5858
clientMu sync.RWMutex
5959
client guestagentclient.GuestAgentClient
60+
61+
guestAgentAliveCh chan struct{} // closed on establishing the connection
62+
guestAgentAliveChOnce sync.Once
6063
}
6164

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

162165
a := &HostAgent{
163-
y: y,
164-
sshLocalPort: sshLocalPort,
165-
udpDNSLocalPort: udpDNSLocalPort,
166-
tcpDNSLocalPort: tcpDNSLocalPort,
167-
instDir: inst.Dir,
168-
instName: instName,
169-
instSSHAddress: inst.SSHAddress,
170-
sshConfig: sshConfig,
171-
portForwarder: newPortForwarder(sshConfig, sshLocalPort, rules, inst.VMType),
172-
driver: limaDriver,
173-
sigintCh: sigintCh,
174-
eventEnc: json.NewEncoder(stdout),
175-
vSockPort: vSockPort,
166+
y: y,
167+
sshLocalPort: sshLocalPort,
168+
udpDNSLocalPort: udpDNSLocalPort,
169+
tcpDNSLocalPort: tcpDNSLocalPort,
170+
instDir: inst.Dir,
171+
instName: instName,
172+
instSSHAddress: inst.SSHAddress,
173+
sshConfig: sshConfig,
174+
portForwarder: newPortForwarder(sshConfig, sshLocalPort, rules, inst.VMType),
175+
driver: limaDriver,
176+
sigintCh: sigintCh,
177+
eventEnc: json.NewEncoder(stdout),
178+
vSockPort: vSockPort,
179+
guestAgentAliveCh: make(chan struct{}),
176180
}
177181
return a, nil
178182
}
@@ -492,6 +496,21 @@ sudo chown -R "${USER}" /run/host-services`
492496
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
493497
errs = append(errs, err)
494498
}
499+
if !*a.y.Plain {
500+
logrus.Info("Waiting for the guest agent to be running")
501+
select {
502+
case <-a.guestAgentAliveCh:
503+
// NOP
504+
case <-time.After(time.Minute):
505+
err := errors.New("guest agent does not seem to be running; port forwards will not work")
506+
if *a.y.VMType == limayaml.WSL2 {
507+
// geustagent is currently not available for WSL2: https://github.com/lima-vm/lima/issues/2025
508+
logrus.Warn(err)
509+
} else {
510+
errs = append(errs, err)
511+
}
512+
}
513+
}
495514
if err := a.waitForRequirements("final", a.finalRequirements()); err != nil {
496515
errs = append(errs, err)
497516
}
@@ -605,6 +624,10 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client guestage
605624
if err != nil {
606625
return err
607626
}
627+
logrus.Info("Guest agent is running")
628+
a.guestAgentAliveChOnce.Do(func() {
629+
close(a.guestAgentAliveCh)
630+
})
608631

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

pkg/hostagent/requirements.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/lima-vm/lima/pkg/limayaml"
9-
"github.com/lima-vm/lima/pkg/store/filenames"
109
"github.com/lima-vm/sshocker/pkg/ssh"
1110
"github.com/sirupsen/logrus"
1211
)
@@ -120,40 +119,6 @@ fi
120119
debugHint: `Append "user_allow_other" to /etc/fuse.conf (/etc/fuse3.conf) in the guest`,
121120
})
122121
}
123-
if a.vSockPort != 0 {
124-
req = append(req, requirement{
125-
description: "the guest agent to be running",
126-
script: fmt.Sprintf(`#!/bin/bash
127-
set -eux -o pipefail
128-
if ! timeout 30s bash -c "until ss -a -n --vsock --listen | grep -q ':%d'; do sleep 3; done"; then
129-
echo >&2 "lima-guestagent is not installed yet"
130-
exit 1
131-
fi
132-
`, a.vSockPort),
133-
debugHint: fmt.Sprintf(`The guest agent with vsockPort %d does not seem running.
134-
Make sure that you are using an officially supported image.
135-
Also see "/var/log/cloud-init-output.log" in the guest.
136-
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
137-
`, a.vSockPort),
138-
})
139-
} else {
140-
req = append(req, requirement{
141-
description: "the guest agent to be running",
142-
script: fmt.Sprintf(`#!/bin/bash
143-
set -eux -o pipefail
144-
sock="/dev/virtio-ports/%s"
145-
if ! timeout 30s bash -c "until sudo fuser \"${sock}\" || sudo lsof \"${sock}\"; do sleep 3; done"; then
146-
echo >&2 "lima-guestagent is not installed yet"
147-
exit 1
148-
fi
149-
`, filenames.VirtioPort),
150-
debugHint: fmt.Sprintf(`The guest agent with serialport /dev/virtio-ports/%s does not seem running.
151-
Make sure that you are using an officially supported image.
152-
Also see "/var/log/cloud-init-output.log" in the guest.
153-
A possible workaround is to run "lima-guestagent install-systemd" in the guest.
154-
`, filenames.VirtioPort),
155-
})
156-
}
157122
return req
158123
}
159124

0 commit comments

Comments
 (0)