go/clitable: factor out from metroctl
We need the same functionality in bmcli, so factor it out from metroctl
into a generic library.
Change-Id: I3fb3dfaae44a64d204e9220f117f379c382c5c4f
Reviewed-on: https://review.monogon.dev/c/monogon/+/2172
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/cli/metroctl/table_node.go b/metropolis/cli/metroctl/table_node.go
index c708443..07f994c 100644
--- a/metropolis/cli/metroctl/table_node.go
+++ b/metropolis/cli/metroctl/table_node.go
@@ -5,24 +5,25 @@
"sort"
"strings"
+ "source.monogon.dev/go/clitable"
"source.monogon.dev/metropolis/node/core/identity"
apb "source.monogon.dev/metropolis/proto/api"
cpb "source.monogon.dev/metropolis/proto/common"
)
-func nodeEntry(n *apb.Node) entry {
- res := entry{}
+func nodeEntry(n *apb.Node) clitable.Entry {
+ res := clitable.Entry{}
- res.add("node id", identity.NodeID(n.Pubkey))
+ res.Add("node id", identity.NodeID(n.Pubkey))
state := n.State.String()
state = strings.ReplaceAll(state, "NODE_STATE_", "")
- res.add("state", state)
+ res.Add("state", state)
address := "unknown"
if n.Status != nil && n.Status.ExternalAddress != "" {
address = n.Status.ExternalAddress
}
- res.add("address", address)
- res.add("health", n.Health.String())
+ res.Add("address", address)
+ res.Add("health", n.Health.String())
var roles []string
if n.Roles.ConsensusMember != nil {
@@ -35,7 +36,7 @@
roles = append(roles, "KubernetesWorker")
}
sort.Strings(roles)
- res.add("roles", strings.Join(roles, ","))
+ res.Add("roles", strings.Join(roles, ","))
tpm := "unk"
switch n.TpmUsage {
@@ -46,10 +47,10 @@
case cpb.NodeTPMUsage_NODE_TPM_NOT_PRESENT:
tpm = "no"
}
- res.add("tpm", tpm)
+ res.Add("tpm", tpm)
tshs := n.TimeSinceHeartbeat.GetSeconds()
- res.add("heartbeat", fmt.Sprintf("%ds", tshs))
+ res.Add("heartbeat", fmt.Sprintf("%ds", tshs))
return res
}