Skip to content

Add support for collecting instance IP address #3696

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

songponssw
Copy link
Contributor

@songponssw songponssw commented Jul 5, 2025

What does this PR do?

Implementation details

With GuestAgent:

  • The raw output from ip -j a is embedded as json_bytes in the gRPC Events message.
  • The GuestAgent listens for this event, extracts the IP information, and writes it to the instance_info.json file.

Without GuestAgent (Plain mode):

  • This PR updates the executeSSH() function signature to return both the command output and error (instead of just error).
  • After completing any requirements setup, HostAgent uses executeSSH() to run ip -j a, processes the output, and writes the instance info locally.

Testing

  • Setup: Lima upstream master, OS(Ubuntu 22.02)
  • templates: almalinux alpine debian fedora opensuse oraclelinux ubuntu
  • Test command: limactl start INSTNAME --network lima:user-v2
  • Result
    • With GuestAgent: All tests passed.
    • Plain Mode: Failed on AlmaLinux and Alpine — instances did not start successfully.

@songponssw songponssw force-pushed the guestagent-send-ip branch 2 times, most recently from ce812d0 to 7e5a9ee Compare July 6, 2025 04:25
@@ -186,6 +188,24 @@ func (a *agent) collectEvent(ctx context.Context, st eventState) (*api.Event, ev
}
ev.LocalPortsAdded, ev.LocalPortsRemoved = comparePorts(st.ports, newSt.ports)
ev.Time = timestamppb.Now()

// Get network interfaces info
cmd := exec.Command("ip", "-j", "a")
Copy link
Member

Choose a reason for hiding this comment

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

Does this really work with busybox?

Copy link
Member

@jandubois jandubois Jul 7, 2025

Choose a reason for hiding this comment

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

It works with the Alpine cloud image from template://alpine. It does not work with alpine-lima from template://alpine-iso, but can easily be made to work by adding the iproute2 package to the image.

PS: I assume this question was about Alpine, and not busybox because the ip -j a would be executed in the guest and not in a container.

Copy link
Member

Choose a reason for hiding this comment

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

I just used a shell script for apple container, since it "forgot" to update the /etc/hosts file.

echo "127.0.0.1 localhost" >/etc/hosts
echo "$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) $(hostname)" >>/etc/hosts

Copy link
Member

Choose a reason for hiding this comment

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

I thought that Alpine used ip from busybox by default, but maybe that is what you are saying above

Copy link
Member

Choose a reason for hiding this comment

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

A minimal Alpine uses just busybox, but you can apk add iproute2 to install the real one. Our alpine-lima ISO image is the only one that is using busybox ip by default.

@songponssw songponssw marked this pull request as draft July 7, 2025 08:16
jandubois added a commit to jandubois/alpine-lima that referenced this pull request Jul 7, 2025
Added unconditionally to all editions because in the future Lima will
depend on it (it is also part of the default Alpine cloud image).

Ref lima-vm/lima#3696

Signed-off-by: Jan Dubois <[email protected]>
@songponssw songponssw force-pushed the guestagent-send-ip branch from 7e5a9ee to eb07981 Compare July 11, 2025 20:04
@songponssw
Copy link
Contributor Author

songponssw commented Jul 11, 2025

Changes – Draft 2 (edited)

gRPC

  • added CommandOutput message to hold output from the client.
  • Created dedicated endpoints for GetIPv4 and GetIPv6.

Hostagent

  • agent get ipaddress as the last step in host agent routine and it should all only when the instance spin up.
  • Stores IP addresses internally
  • Exports IP address through the Info strut in hostagent/api

CLI

  • Added IPv4Address and IPv6Address fields
  • IP address are now available, e.g.: limactl ls --format "{{ .Name }} {{ .IPv4Address }}"

Note;

  • IPv6 is currently unavailable; no default route is found.
  • gRPC compiled grpc with protoc-compiler 6.30.2

P.S. I'm trying my best to follow the design patterns found in the existing code. If there are any points that need refactoring, please let me know.

@songponssw songponssw force-pushed the guestagent-send-ip branch 2 times, most recently from df9c498 to 3ba87dc Compare July 12, 2025 13:21
@songponssw songponssw force-pushed the guestagent-send-ip branch from 3ba87dc to 438de9f Compare July 12, 2025 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Report VM IP addresses to host agent
4 participants