backport of commit d2849b8a7678110f2c4643d5036ab55e6872770b (#19161)
Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
This commit is contained in:
parent
17e7e0d330
commit
4701162b2d
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
cli: Fixed a bug that caused the `nomad job restart` command to miscount the allocations to restart
|
||||
```
|
|
@ -633,6 +633,19 @@ func (c *JobRestartCommand) filterAllocs(stubs []AllocationListStubWithJob) []Al
|
|||
continue
|
||||
}
|
||||
|
||||
// Skip allocations that have already been replaced.
|
||||
if stub.NextAllocation != "" {
|
||||
if c.verbose {
|
||||
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
|
||||
"[dark_gray] %s: Skipping allocation %q because it has already been replaced by %q[reset]",
|
||||
formatTime(time.Now()),
|
||||
shortAllocID,
|
||||
limit(stub.NextAllocation, c.length),
|
||||
)))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Skip allocations for groups that were not requested.
|
||||
if c.groups.Size() > 0 {
|
||||
if !c.groups.Contains(stub.TaskGroup) {
|
||||
|
|
|
@ -1245,6 +1245,21 @@ func TestJobRestartCommand_filterAllocs(t *testing.T) {
|
|||
}
|
||||
allocs[key] = alloc
|
||||
allAllocs = append(allAllocs, alloc)
|
||||
|
||||
// Allocations with a replacement must always be skipped.
|
||||
replacedAlloc := AllocationListStubWithJob{
|
||||
AllocationListStub: &api.AllocationListStub{
|
||||
ID: key,
|
||||
JobVersion: *job.Version,
|
||||
TaskGroup: *tg.Name,
|
||||
DesiredStatus: desired,
|
||||
ClientStatus: client,
|
||||
NextAllocation: alloc.ID,
|
||||
},
|
||||
Job: job,
|
||||
}
|
||||
allocs[key+"_replaced"] = replacedAlloc
|
||||
allAllocs = append(allAllocs, replacedAlloc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue