Skip to content

Commit

Permalink
Random name when not provided (#153)
Browse files Browse the repository at this point in the history
* nodes are initialized with random name
  • Loading branch information
jordan-rash committed Mar 27, 2024
1 parent 5325766 commit 7bca90e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/splode/fname v0.4.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5 // indirect
github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/splode/fname v0.4.1 h1:tRBvCEoNMKMI9veue+LZ7psUFWHWRRX+rmWhqUjzmog=
github.com/splode/fname v0.4.1/go.mod h1:73RiaoonLZF/9E7lvIoxj/y2ZVfq7Gq2tNvPwADQx/8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
10 changes: 9 additions & 1 deletion internal/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"

"github.com/splode/fname"
agentapi "github.com/synadia-io/nex/internal/agent-api"
)

Expand Down Expand Up @@ -109,6 +110,13 @@ func DefaultNodeConfiguration() NodeConfiguration {
defaultVcpuCount := defaultNodeVcpuCount
defaultMemSizeMib := defaultNodeMemSizeMib

tags := make(map[string]string)
rng := fname.NewGenerator()
nodeName, err := rng.Generate()
if err == nil {
tags["node_name"] = nodeName
}

return NodeConfiguration{
BinPath: defaultBinPath,
CNI: CNIDefinition{
Expand All @@ -125,7 +133,7 @@ func DefaultNodeConfiguration() NodeConfiguration {
VcpuCount: &defaultVcpuCount,
MemSizeMib: &defaultMemSizeMib,
},
Tags: make(map[string]string),
Tags: tags,
RateLimiters: nil,
WorkloadTypes: defaultWorkloadTypes,
}
Expand Down
8 changes: 4 additions & 4 deletions nex/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func renderNodeList(nodes []controlapi.PingResponse) {
}

table := newTableWriter("NATS Execution Nodes")
table.AddHeaders("ID", "Hostname", "Version", "Uptime", "Workloads")
table.AddHeaders("ID", "Name", "Version", "Uptime", "Workloads")

for _, node := range nodes {
hostName, ok := node.Tags["hostname"]
nodeName, ok := node.Tags["node_name"]
if !ok {
hostName = ""
nodeName = "no-name-provided"
}
table.AddRow(node.NodeId, hostName, node.Version, node.Uptime, node.RunningMachines)
table.AddRow(node.NodeId, nodeName, node.Version, node.Uptime, node.RunningMachines)
}

fmt.Println(table.Render())
Expand Down

0 comments on commit 7bca90e

Please sign in to comment.