Skip to content

Commit

Permalink
Fix panic when listing serverless instances
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysdabro committed Mar 2, 2024
1 parent 4f9583e commit 5f2d193
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
12 changes: 9 additions & 3 deletions internal/show/minimal/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package minimal
import (
"bytes"
"fmt"
"strconv"
"strings"

"github.com/lynn9388/supsub"
Expand All @@ -33,13 +32,20 @@ var (
zone = n.Zones[0]
}
az := zone[len(zone)-2:]
cpu := strconv.Itoa(n.Compute.CPU.Cores)

cpu := "-"
mem := "-"
if n.Compute != nil {
cpu = fmt.Sprintf("%dx", n.Compute.CPU.Cores)
mem = n.Compute.Memory.Size.String()
}

role := ""
if n.ReadOnly {
role = "ro"
}

text := fmt.Sprintf("%2s %-17s %-6s %-15s %2sx %7s %8s %-6s %2s %s\n", az, n.Engine.ID, n.Engine.Version, n.Type, cpu, n.Compute.Memory.Size, n.Storage.Size, n.Storage.Type, role, n.Name)
text := fmt.Sprintf("%2s %-17s %-6s %-15s %3s %7s %8s %-6s %2s %s\n", az, n.Engine.ID, n.Engine.Version, n.Type, cpu, mem, n.Storage.Size, n.Storage.Type, role, n.Name)
return []byte(text), nil
},
)
Expand Down
22 changes: 18 additions & 4 deletions internal/show/verbose/verbose.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ var (
// Zones ¦ eu-central-1b
showConfigNode = show.FromShow[types.Node](
func(node types.Node) ([]byte, error) {
cpu := "-"
mem := "-"
if node.Compute != nil {
cpu = node.Compute.CPU.String()
mem = node.Compute.Memory.String()
}

ro := ""
if node.ReadOnly {
ro = " (read-only)"
Expand All @@ -43,8 +50,8 @@ var (
b.WriteString(fmt.Sprintf("\n%s%s\n", node.Name, ro))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Engine", node.Engine))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Instance", node.Type))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "CPU", node.Compute.CPU))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Memory", node.Compute.Memory))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "CPU", cpu))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Memory", mem))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Storage", node.Storage))
b.WriteString(fmt.Sprintf("\t%9s ¦ %s\n", "Zones", strings.Join(node.Zones, ", ")))
return b.Bytes(), nil
Expand Down Expand Up @@ -126,6 +133,13 @@ var (
func(node types.StatusNode) ([]byte, error) {
status := show.StatusText(node.Status)

cpu := "-"
mem := "-"
if node.Node.Compute != nil {
cpu = node.Node.Compute.CPU.String()
mem = node.Node.Compute.Memory.String()
}

ro := ""
if node.Node.ReadOnly {
ro = " (read-only)"
Expand All @@ -135,8 +149,8 @@ var (
b.WriteString(fmt.Sprintf("%s %s%s\n", status, node.Node.Name, ro))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "Engine", node.Node.Engine))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "Instance", node.Node.Type))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "CPU", node.Node.Compute.CPU))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "Memory", node.Node.Compute.Memory))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "CPU", cpu))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "Memory", mem))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n", "Storage", node.Node.Storage))
b.WriteString(fmt.Sprintf("%14s ¦ %s\n\n", "Zones", strings.Join(node.Node.Zones, ", ")))
return b.Bytes(), nil
Expand Down

0 comments on commit 5f2d193

Please sign in to comment.