Skip to content

Commit

Permalink
csi: avoid panic in CLI for failed node attachment cleanup (#8525)
Browse files Browse the repository at this point in the history
If the node API returns an attached volume that doesn't belong to an
alloc (because it's failed to clean up properly), `nomad node status`
will panic when rendering the response.

Also, avoid empty volumes output in node status
  • Loading branch information
tgross committed Jul 24, 2020
1 parent f651278 commit 21a4f60
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions command/node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,6 @@ func (c *NodeStatusCommand) outputTruncatedNodeDriverInfo(node *api.Node) string
}

func (c *NodeStatusCommand) outputNodeVolumeInfo(node *api.Node) {
c.Ui.Output(c.Colorize().Color("\n[bold]Host Volumes"))

names := make([]string, 0, len(node.HostVolumes))
for name := range node.HostVolumes {
Expand All @@ -529,15 +528,17 @@ func (c *NodeStatusCommand) outputNodeVolumeInfo(node *api.Node) {
output := make([]string, 0, len(names)+1)
output = append(output, "Name|ReadOnly|Source")

for _, volName := range names {
info := node.HostVolumes[volName]
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
if len(names) > 0 {
c.Ui.Output(c.Colorize().Color("\n[bold]Host Volumes"))
for _, volName := range names {
info := node.HostVolumes[volName]
output = append(output, fmt.Sprintf("%s|%v|%s", volName, info.ReadOnly, info.Path))
}
c.Ui.Output(formatList(output))
}
c.Ui.Output(formatList(output))
}

func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *api.Node, runningAllocs []*api.Allocation) {
c.Ui.Output(c.Colorize().Color("\n[bold]CSI Volumes"))

// Duplicate nodeCSIVolumeNames to sort by name but also index volume names to ids
var names []string
Expand All @@ -563,27 +564,33 @@ func (c *NodeStatusCommand) outputNodeCSIVolumeInfo(client *api.Client, node *ap
volumes := map[string]*api.CSIVolumeListStub{}
vs, _ := client.Nodes().CSIVolumes(node.ID, nil)
for _, v := range vs {
n := requests[v.ID].Name
volumes[n] = v
n, ok := requests[v.ID]
if ok {
volumes[n.Name] = v
}
}

// Output the volumes in name order
output := make([]string, 0, len(names)+1)
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
for _, name := range names {
v := volumes[name]
output = append(output, fmt.Sprintf(
"%s|%s|%s|%t|%s|%s",
v.ID,
name,
v.PluginID,
v.Schedulable,
v.Provider,
v.AccessMode,
))
}

c.Ui.Output(formatList(output))
if len(names) > 0 {
c.Ui.Output(c.Colorize().Color("\n[bold]CSI Volumes"))

// Output the volumes in name order
output := make([]string, 0, len(names)+1)
output = append(output, "ID|Name|Plugin ID|Schedulable|Provider|Access Mode")
for _, name := range names {
v := volumes[name]
output = append(output, fmt.Sprintf(
"%s|%s|%s|%t|%s|%s",
v.ID,
name,
v.PluginID,
v.Schedulable,
v.Provider,
v.AccessMode,
))
}

c.Ui.Output(formatList(output))
}
}

func (c *NodeStatusCommand) outputNodeDriverInfo(node *api.Node) {
Expand Down

0 comments on commit 21a4f60

Please sign in to comment.