69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package node
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/charmbracelet/bubbles/list"
|
|
"github.com/siderolabs/talos/pkg/machinery/config/machine"
|
|
)
|
|
|
|
type ListItem struct {
|
|
Node *Node
|
|
}
|
|
|
|
func (i *ListItem) FilterValue() string {
|
|
return fmt.Sprintf("%s %s %s", i.Node.Spec.Hostname, i.Node.Spec.MachineType.String(), i.Node.Spec.OperatingSystem)
|
|
}
|
|
|
|
func (i *ListItem) Title() string {
|
|
return i.Node.Spec.Hostname
|
|
}
|
|
|
|
func (i *ListItem) Description() string {
|
|
var nodeType = "worker"
|
|
|
|
if i == nil || i.Node == nil {
|
|
return "invalid node"
|
|
}
|
|
|
|
nodeVersion, err := i.Node.Version()
|
|
if err != nil {
|
|
nodeVersion = "invalid version"
|
|
}
|
|
|
|
if i.Node.Spec.MachineType == machine.TypeControlPlane {
|
|
nodeType = "controlplane"
|
|
}
|
|
|
|
return fmt.Sprintf("%s (%s)", nodeVersion, nodeType)
|
|
}
|
|
|
|
func ListFromNodes(in []*Node) list.Model {
|
|
items := make([]list.Item, len(in))
|
|
|
|
for i, n := range in {
|
|
item := &ListItem{Node: n}
|
|
|
|
items[i] = item
|
|
}
|
|
|
|
return list.New(items, list.NewDefaultDelegate(), 0, 0)
|
|
}
|
|
|
|
// NotVersion filters the list of Nodes, removing all Nodes which are the given version.
|
|
func NotVersion(in []*Node, version string) (out []*Node) {
|
|
for _, n := range in {
|
|
nodeVersion, err := n.Version()
|
|
if err != nil {
|
|
nodeVersion = "invalid version"
|
|
}
|
|
|
|
if version == nodeVersion {
|
|
continue
|
|
}
|
|
|
|
out = append(out, n)
|
|
}
|
|
|
|
return
|
|
}
|