Skip to content

Commit

Permalink
Merge pull request #50 from pw-git/add-ips-to-get-pod
Browse files Browse the repository at this point in the history
feat: IPs and port mappings in pod get output
  • Loading branch information
DireLines authored Apr 12, 2024
2 parents 8dd71c2 + b8426d9 commit 83c2691
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
15 changes: 8 additions & 7 deletions api/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ type Machine struct {
GpuDisplayName string
}
type Runtime struct {
Ports []*PodRuntimePorts
Ports []*Ports
}
type PodRuntimePorts struct {

type Ports struct {
Ip string
IsIpPublic bool
PrivatePort int
PublicPort int
Type string
PortType string
}

func GetPods() (pods []*Pod, err error) {
Expand Down Expand Up @@ -92,12 +93,12 @@ func GetPods() (pods []*Pod, err error) {
gpuDisplayName
}
runtime {
ports {
ports {
ip
publicPort
privatePort
isIpPublic
type
privatePort
publicPort
PortType: type
}
}
}
Expand Down
17 changes: 16 additions & 1 deletion cmd/pod/getPod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ var GetPodCmd = &cobra.Command{
}
row := []string{p.Id, p.Name, fmt.Sprintf("%d %s", p.GpuCount, p.Machine.GpuDisplayName), p.ImageName, p.DesiredStatus}
if AllFields {

var portEntries int = 0
if p.Runtime != nil && p.Runtime.Ports != nil {
portEntries = len(p.Runtime.Ports)
}
ports := make([]string, portEntries)
for j := range ports {
var privpub string = "prv"
if p.Runtime.Ports[j].IsIpPublic {
privpub = "pub"
}
ports[j] = fmt.Sprintf("%s:%d->%d\u00A0(%s,%s)", p.Runtime.Ports[j].Ip, p.Runtime.Ports[j].PublicPort, p.Runtime.Ports[j].PrivatePort, privpub, p.Runtime.Ports[j].PortType)
}

row = append(
row,
p.PodType,
Expand All @@ -38,14 +52,15 @@ var GetPodCmd = &cobra.Command{
fmt.Sprintf("%d", p.ContainerDiskInGb),
fmt.Sprintf("%d", p.VolumeInGb),
fmt.Sprintf("%.3f", p.CostPerHr),
fmt.Sprintf("%s", strings.Join(ports[:], ",")),
)
}
data[i] = row
}

header := []string{"ID", "Name", "GPU", "Image Name", "Status"}
if AllFields {
header = append(header, "Pod Type", "vCPU", "Mem", "Container Disk", "Volume Disk", "$/hr")
header = append(header, "Pod Type", "vCPU", "Mem", "Container Disk", "Volume Disk", "$/hr", "Ports")
}

tb := tablewriter.NewWriter(os.Stdout)
Expand Down

0 comments on commit 83c2691

Please sign in to comment.