mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
cli: skip allocs with replacements on job restart (#19155)
The `nomad job restart` command should skip allocations that already have replacements. Restarting an allocation with a replacement is a no-op because the allocation status is terminal and the command's replacement monitor returns immediatelly. But by not skipping them, the effective batch size is computed incorrectly.
This commit is contained in:
3
.changelog/19155.txt
Normal file
3
.changelog/19155.txt
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user