From 482678b3ed408772429f50785908f8f233d1471e Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 24 Nov 2023 10:37:06 +0900 Subject: [PATCH 1/2] hostagent: avoid requiring `fuser` and `ss` in the guest No need to check the guestagent socket with `fuser` or `ss`, if the guestagent is actually functional Fix issue 2010 Signed-off-by: Akihiro Suda --- pkg/hostagent/hostagent.go | 49 +++++++++++++++++++++++++---------- pkg/hostagent/requirements.go | 35 ------------------------- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/pkg/hostagent/hostagent.go b/pkg/hostagent/hostagent.go index b1de13115e3..b7f59fefbcc 100644 --- a/pkg/hostagent/hostagent.go +++ b/pkg/hostagent/hostagent.go @@ -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 { @@ -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 } @@ -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) } @@ -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) diff --git a/pkg/hostagent/requirements.go b/pkg/hostagent/requirements.go index 8f786bf87a3..8745c6349e6 100644 --- a/pkg/hostagent/requirements.go +++ b/pkg/hostagent/requirements.go @@ -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" ) @@ -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 } From d1e52c9e574d905eafce881c0fb3c28a870e5f6e Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Sat, 18 Nov 2023 05:24:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?CI:=20update=20colima=20(v0.5.5=E2=86=92v0.?= =?UTF-8?q?6.5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Akihiro Suda --- .github/workflows/test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ed3a7ba344..9153702b12a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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