mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
stateful deployments: fix missing prefix search in claim list CLI (#25297)
This commit is contained in:
committed by
GitHub
parent
69c2ed55d5
commit
29c7b7ca44
@@ -30,7 +30,7 @@ type VolumeClaimListCommand struct {
|
||||
|
||||
func (c *VolumeClaimListCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: nomad volume claim list [options]
|
||||
Usage: nomad volume claim list [options] [claim_id]
|
||||
|
||||
volume claim list is used to list existing host volume claims.
|
||||
|
||||
@@ -98,9 +98,10 @@ func (c *VolumeClaimListCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Check that we got no arguments
|
||||
if len(flags.Args()) != 0 {
|
||||
c.Ui.Error("This command takes no arguments")
|
||||
// Check that we either got no arguments or exactly one
|
||||
args = flags.Args()
|
||||
if len(args) > 1 {
|
||||
c.Ui.Error("This command takes either no arguments or one: <id>")
|
||||
c.Ui.Error(commandErrorText(c))
|
||||
return 1
|
||||
}
|
||||
@@ -118,11 +119,20 @@ func (c *VolumeClaimListCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
claims, _, err := client.TaskGroupHostVolumeClaims().List(&api.TaskGroupHostVolumeClaimsListRequest{
|
||||
JobID: c.job,
|
||||
TaskGroup: c.taskGroup,
|
||||
VolumeName: c.volumeName,
|
||||
}, nil)
|
||||
id := ""
|
||||
if len(args) == 1 {
|
||||
id = args[0]
|
||||
}
|
||||
|
||||
claims, _, err := client.TaskGroupHostVolumeClaims().List(
|
||||
&api.TaskGroupHostVolumeClaimsListRequest{
|
||||
JobID: c.job,
|
||||
TaskGroup: c.taskGroup,
|
||||
VolumeName: c.volumeName,
|
||||
},
|
||||
&api.QueryOptions{
|
||||
Prefix: id,
|
||||
})
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error listing task group host volume claims: %s", err))
|
||||
return 1
|
||||
|
||||
@@ -127,4 +127,20 @@ func TestVolumeClaimListCommand_Run(t *testing.T) {
|
||||
}
|
||||
|
||||
ui.OutputWriter.Reset()
|
||||
|
||||
// Prefix list
|
||||
must.Zero(t, cmd.Run([]string{
|
||||
"-address=" + url,
|
||||
"-token=" + token.SecretID,
|
||||
"-verbose",
|
||||
existingClaims[0].ID[0:2],
|
||||
}))
|
||||
out = ui.OutputWriter.String()
|
||||
|
||||
must.StrContains(t, out, existingClaims[0].ID)
|
||||
for _, id := range []string{existingClaims[1].ID, existingClaims[2].ID, existingClaims[3].ID, existingClaims[4].ID} {
|
||||
must.StrNotContains(t, out, id, must.Sprintf("did not expect to find %s in %s", id, out))
|
||||
}
|
||||
|
||||
ui.OutputWriter.Reset()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user