Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Nomad agent version to the node-status CLI output. #3002

Merged
merged 2 commits into from
Aug 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type NodeListStub struct {
Datacenter string
Name string
NodeClass string
Build string
Drain bool
Status string
StatusDescription string
Expand Down
1 change: 1 addition & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func (a *Agent) clientConfig() (*clientconfig.Config, error) {
conf.Node.Name = a.config.NodeName
conf.Node.Meta = a.config.Client.Meta
conf.Node.NodeClass = a.config.Client.NodeClass
conf.Node.Build = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)

// Set up the HTTP advertise address
conf.Node.HTTPAddr = a.config.AdvertiseAddrs.HTTP
Expand Down
17 changes: 10 additions & 7 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Node Status Options:
-self
Query the status of the local node.

-stats
-stats
Display detailed resource usage statistics.

-allocs
Expand Down Expand Up @@ -149,9 +149,9 @@ func (c *NodeStatusCommand) Run(args []string) int {
// Format the nodes list
out := make([]string, len(nodes)+1)
if c.list_allocs {
out[0] = "ID|DC|Name|Class|Drain|Status|Running Allocs"
out[0] = "ID|DC|Name|Class|Build|Drain|Status|Running Allocs"
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep it for only -verbose. Most people aren't running mixed clusters so it will just needlessly expand the width of output

Copy link
Member Author

@jrasell jrasell Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on how to best accomplish this @dadgar? From my understanding verbose is currently only used to determine the length of the nodeID displayed. I am trying to avoid using numerous else ifs to reconcile the differences between the -allocs and -verbose flag usage:

if c.list_allocs && !c.verbose {
    out[0] = "ID|DC|Name|Class|Drain|Status|Running Allocs"
} else if c.list_allocs && c.verbose {
    out[0] = "ID|DC|Name|Class|Build|Drain|Status|Running Allocs"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you may want to try breaking it into:

out := "ID|DC|Name|Class|"
if c.verbose {
  out += "Version|"
}
out += "Drain|Status"
if c.list_allocs {
  out += "|Running Allocs"
}

out[0] = "ID|DC|Name|Class|Drain|Status"
out[0] = "ID|DC|Name|Class|Build|Drain|Status"
}

for i, node := range nodes {
Expand All @@ -161,20 +161,22 @@ func (c *NodeStatusCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Error querying node allocations: %s", err))
return 1
}
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s|%v",
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%v|%s|%v",
limit(node.ID, c.length),
node.Datacenter,
node.Name,
node.NodeClass,
node.Build,
node.Drain,
node.Status,
len(numAllocs))
} else {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s",
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%v|%s",
limit(node.ID, c.length),
node.Datacenter,
node.Name,
node.NodeClass,
node.Build,
node.Drain,
node.Status)
}
Expand Down Expand Up @@ -220,13 +222,14 @@ func (c *NodeStatusCommand) Run(args []string) int {
// Format the nodes list that matches the prefix so that the user
// can create a more specific request
out := make([]string, len(nodes)+1)
out[0] = "ID|DC|Name|Class|Drain|Status"
out[0] = "ID|DC|Name|Class|Build|Drain|Status"
for i, node := range nodes {
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%v|%s",
out[i+1] = fmt.Sprintf("%s|%s|%s|%s|%s|%v|%s",
limit(node.ID, c.length),
node.Datacenter,
node.Name,
node.NodeClass,
node.Build,
node.Drain,
node.Status)
}
Expand Down
5 changes: 5 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,9 @@ type Node struct {
// together for the purpose of determining scheduling pressure.
NodeClass string

// Build represents the Nomad version the node is running
Build string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove from the Node struct and only add to the stub


// ComputedClass is a unique id that identifies nodes with a common set of
// attributes and capabilities.
ComputedClass string
Expand Down Expand Up @@ -1057,6 +1060,7 @@ func (n *Node) Stub() *NodeListStub {
Datacenter: n.Datacenter,
Name: n.Name,
NodeClass: n.NodeClass,
Build: n.Build,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pull this out of the attributes map. The key is nomad.version

Drain: n.Drain,
Status: n.Status,
StatusDescription: n.StatusDescription,
Expand All @@ -1072,6 +1076,7 @@ type NodeListStub struct {
Datacenter string
Name string
NodeClass string
Build string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build -> Version

Drain bool
Status string
StatusDescription string
Expand Down