Skip to content

Commit

Permalink
csi: allow volume detach to take a node ID prefix
Browse files Browse the repository at this point in the history
Fixes a bug where the `nomad volume detach` command would not accept a node ID
prefix instead of a full node ID. The volume ID is already prefix matched
server-side.
  • Loading branch information
tgross committed Oct 7, 2020
1 parent 98a7834 commit b42b838
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ BUG FIXES:

* core: Fixed a bug where blocking queries would not include the query's maximum wait time when calculating whether it was safe to retry. [[GH-8921](https://github.com/hashicorp/nomad/issues/8921)]
* consul: Fixed a bug to correctly validate task when using script-checks in group-level services [[GH-8952](https://github.com/hashicorp/nomad/issues/8952)]
* csi: Fixed a bug where `nomad volume detach` would not accept prefixes for the node ID parameter. [[GH-9041](https://github.com/hashicorp/nomad/issues/9041)]

## 0.12.5 (September 17, 2020)

Expand Down
19 changes: 18 additions & 1 deletion command/volume_detach.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,24 @@ func (c *VolumeDetachCommand) Run(args []string) int {
return 1
}

err = client.CSIVolumes().Detach(volID, nodeID, nil)
nodeID = sanitizeUUIDPrefix(nodeID)
nodes, _, err := client.Nodes().PrefixList(nodeID)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error detaching volume: %s", err))
return 1
}
// Return error if no nodes are found
if len(nodes) == 0 {
c.Ui.Error(fmt.Sprintf("No node(s) with prefix or id %q found", nodeID))
return 1
}
if len(nodes) > 1 {
c.Ui.Error(fmt.Sprintf("Prefix matched multiple nodes\n\n%s",
formatNodeStubList(nodes, true)))
return 1
}

err = client.CSIVolumes().Detach(volID, nodes[0].ID, nil)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error detaching volume: %s", err))
return 1
Expand Down

0 comments on commit b42b838

Please sign in to comment.