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

hostagent: avoid requiring fuser and ss in the guest ; CI: update colima (v0.5.5→v0.6.5) #2009

Merged
merged 2 commits into from
Nov 24, 2023
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
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 }}
Copy link
Contributor

Choose a reason for hiding this comment

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

@AkihiroSuda
Is there a reason for using the PR head commit instead of the PR merge commit? The code being tested might differ from what it will be after the merge, which seems problematic.

The intention here is not clear from reading the PR.
I am currently trying on a PR to consolidate build jobs per platform (#2532), and I'm unsure if it's acceptable to default to using the merge commit. Could you clarify?

Copy link
Member Author

Choose a reason for hiding this comment

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

From my memory limactl --version didn't show the correct version without this, but I could be wrong.
Feel free to remove this in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your response. Based on my testing, git describe returns the expected version string format with just fetch-depth: 0, so it doesn’t seem necessary to set ref:.

- 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
Loading