From cb0df2169f773b1f44506e6cf8ddb23aa62d4e51 Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Fri, 12 Dec 2025 20:23:43 +1000 Subject: [PATCH] feat: add IP ADDRESS column to 'uc ps' and 'uc inspect' --- cmd/uncloud/ps.go | 12 +++++++++++- cmd/uncloud/service/inspect.go | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cmd/uncloud/ps.go b/cmd/uncloud/ps.go index 4a0cb412..b4730924 100644 --- a/cmd/uncloud/ps.go +++ b/cmd/uncloud/ps.go @@ -71,6 +71,7 @@ type containerInfo struct { status string highlight containerHighlight created time.Time + ip string } func runPs(ctx context.Context, uncli *cli.CLI, opts psOptions) error { @@ -142,7 +143,7 @@ func printContainers(containers []containerInfo) error { return lipgloss.NewStyle().PaddingRight(3) }) - t.Headers("SERVICE", "CONTAINER ID", "CONTAINER NAME", "IMAGE", "CREATED", "STATUS", "MACHINE") + t.Headers("SERVICE", "CONTAINER ID", "CONTAINER NAME", "IMAGE", "CREATED", "STATUS", "IP ADDRESS", "MACHINE") for _, ctr := range containers { id := ctr.id @@ -171,6 +172,7 @@ func printContainers(containers []containerInfo) error { ctr.image, created, statusStyle.Render(ctr.status), + ctr.ip, ctr.machineName, ) } @@ -257,6 +259,13 @@ func collectContainers(ctx context.Context, cli *client.Client) ([]containerInfo created, _ := time.Parse(time.RFC3339Nano, ctr.Container.Created) + ip := ctr.Container.UncloudNetworkIP() + ipStr := "" + // The container might not have an IP if it's not running or uses the host network. + if ip.IsValid() { + ipStr = ip.String() + } + info := containerInfo{ serviceName: ctr.ServiceName(), machineName: machineName, @@ -266,6 +275,7 @@ func collectContainers(ctx context.Context, cli *client.Client) ([]containerInfo status: status, highlight: highlight, created: created, + ip: ipStr, } containers = append(containers, info) } diff --git a/cmd/uncloud/service/inspect.go b/cmd/uncloud/service/inspect.go index 8f7c9aca..c87252a3 100644 --- a/cmd/uncloud/service/inspect.go +++ b/cmd/uncloud/service/inspect.go @@ -74,7 +74,7 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error { // Print the list of containers in a table format. tw := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) - if _, err = fmt.Fprintln(tw, "CONTAINER ID\tIMAGE\tCREATED\tSTATUS\tMACHINE"); err != nil { + if _, err = fmt.Fprintln(tw, "CONTAINER ID\tIMAGE\tCREATED\tSTATUS\tIP ADDRESS\tMACHINE"); err != nil { return fmt.Errorf("write header: %w", err) } @@ -91,13 +91,21 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error { return fmt.Errorf("get human state: %w", err) } + ip := ctr.Container.UncloudNetworkIP() + ipStr := "" + // The container might not have an IP if it's not running or uses the host network. + if ip.IsValid() { + ipStr = ip.String() + } + _, err = fmt.Fprintf( tw, - "%s\t%s\t%s\t%s\t%s\n", + "%s\t%s\t%s\t%s\t%s\t%s\n", stringid.TruncateID(ctr.Container.ID), ctr.Container.Config.Image, created, state, + ipStr, machine, ) if err != nil {