google/android-cuttlefish PR #2814 — Add podcvd ps subcommand — PR #2814
google/android-cuttlefish · pull request #2814 ·
Transcript
PlainEnglish
We're looking at pull request twenty-eight fourteen from the Android Cuttlefish project. This PR introduces a new ps subcommand to the podcvd tool, letting users list running instances across all container groups. It's marked work in progress, with around a hundred lines added across two files.
PlainEnglish
Here's what this pull request sets out to do. The main goal is implementing the cvd ps subcommand so users can see all their instances across multiple container groups. Along the way, there's a function rename to make the code clearer, and some translation logic for adb port formats in the output.
PlainEnglish
Before this change, users could see container groups with cvd fleet, but there wasn't a built-in way to list individual Cuttlefish instances across those groups. This PR adds the ps subcommand to give visibility into all running processes with a nicely formatted table.
Architecture
Let's start with the dispatch logic. The main switch statement now recognizes ps as a subcommand, routing it to a new function called psAllCuttlefishHosts. This follows the same pattern as fleet and clear, keeping the structure consistent.
Architecture
Here's the heart of the implementation. The function spins up a goroutine for each container to fetch ps output concurrently. We're using a wait group for synchronization, with buffered channels to collect results and errors. Each goroutine calls cvd ps inside the container, inspects the container metadata, then sends the translated output back through the results channel.
Architecture
After collecting all the ps output, we need to display it nicely. The printPsTable function calculates dynamic column widths by scanning through all rows, then uses those widths with printf format specifiers to produce aligned columns. Simple but effective for readability.
Architecture
There's also a small refactor here. The function that translates network endpoints and paths gets renamed from updateStringOnCvdGroupJsonRaw to updateEndpointAndPathString. The behavior stays the same, but the new name makes it much clearer what the function actually does.
Architecture
And here's the adb port translation logic. The regex matches patterns like adb colon five five five five, then rewrites them to adb colon IP colon port. This ensures the ports in the ps output are visible from the host machine, not just inside the container. Word boundaries in the regex prevent false matches.
PlainEnglish
After this PR lands, users can run podcvd ps to list all Cuttlefish instances across their container groups. They'll see a nicely formatted table with status, timestamps, ports, and web access URLs. Everything's fetched concurrently, and all the network endpoints get translated so they're reachable from the host.
CodeQuality
One thing to keep in mind: the table parser assumes a specific format. It expects at least six whitespace-delimited fields, and it reconstructs the status column by joining everything between the id and the last four fields. If the upstream cvd ps output format ever changes, this logic could silently break. There's no documentation describing the expected column layout.
CodeQuality
There's also no timeout or retry logic on the container calls. Each goroutine uses context dot Background, which means if a container becomes unresponsive, the goroutine will block indefinitely waiting for a response. That could delay the entire ps operation. A context with a timeout would be safer here.
PlainEnglish
So that's pull request twenty-eight fourteen. It's a work-in-progress feature that brings multi-container instance listing to podcvd, with concurrent fetching and smart port translation. There are a few notes around table parsing assumptions and missing timeout logic, but the core functionality looks solid. The table parser and concurrent fetch logic are the main areas to explore if you're reviewing this one.
How this was made
Lenzon read google/android-cuttlefish at pull request #2814 and generated this walkthrough automatically. The narration above is the transcript of what it says.
Explain a pull request from your own repo
Point Lenzon at a repo or a pull request and get a narrated walkthrough like this one.
Try it