@@ -18,14 +18,14 @@ func Node(
18
18
readyNodes []* structs.Node , // list of nodes in the ready state
19
19
notReadyNodes map [string ]struct {}, // list of nodes in DC but not ready, e.g. draining
20
20
taintedNodes map [string ]* structs.Node , // nodes which are down or drain mode (by node id)
21
- allocs []* structs.Allocation , // non-terminal allocations
21
+ live []* structs.Allocation , // non-terminal allocations
22
22
terminal structs.TerminalByNodeByName , // latest terminal allocations (by node id)
23
23
serverSupportsDisconnectedClients bool , // flag indicating whether to apply disconnected client logic
24
24
) * NodeReconcileResult {
25
25
26
26
// Build a mapping of nodes to all their allocs.
27
- nodeAllocs := make (map [string ][]* structs.Allocation , len (allocs ))
28
- for _ , alloc := range allocs {
27
+ nodeAllocs := make (map [string ][]* structs.Allocation , len (live ))
28
+ for _ , alloc := range live {
29
29
nodeAllocs [alloc .NodeID ] = append (nodeAllocs [alloc .NodeID ], alloc )
30
30
}
31
31
@@ -65,15 +65,15 @@ func diffSystemAllocsForNode(
65
65
notReadyNodes map [string ]struct {}, // nodes that are not ready, e.g. draining
66
66
taintedNodes map [string ]* structs.Node , // nodes which are down (by node id)
67
67
required map [string ]* structs.TaskGroup , // set of allocations that must exist
68
- allocs []* structs.Allocation , // non-terminal allocations that exist
68
+ liveAllocs []* structs.Allocation , // non-terminal allocations that exist
69
69
terminal structs.TerminalByNodeByName , // latest terminal allocations (by node, id)
70
70
serverSupportsDisconnectedClients bool , // flag indicating whether to apply disconnected client logic
71
71
) * NodeReconcileResult {
72
72
result := new (NodeReconcileResult )
73
73
74
74
// Scan the existing updates
75
75
existing := make (map [string ]struct {}) // set of alloc names
76
- for _ , exist := range allocs {
76
+ for _ , exist := range liveAllocs {
77
77
// Index the existing node
78
78
name := exist .Name
79
79
existing [name ] = struct {}{}
@@ -108,7 +108,7 @@ func diffSystemAllocsForNode(
108
108
}
109
109
110
110
// If we have been marked for migration and aren't terminal, migrate
111
- if ! exist . TerminalStatus () && exist .DesiredTransition .ShouldMigrate () {
111
+ if exist .DesiredTransition .ShouldMigrate () {
112
112
result .Migrate = append (result .Migrate , AllocTuple {
113
113
Name : name ,
114
114
TaskGroup : tg ,
@@ -117,16 +117,6 @@ func diffSystemAllocsForNode(
117
117
continue
118
118
}
119
119
120
- // If we are a sysbatch job and terminal, ignore (or stop?) the alloc
121
- if job .Type == structs .JobTypeSysBatch && exist .TerminalStatus () {
122
- result .Ignore = append (result .Ignore , AllocTuple {
123
- Name : name ,
124
- TaskGroup : tg ,
125
- Alloc : exist ,
126
- })
127
- continue
128
- }
129
-
130
120
// Expired unknown allocs are lost. Expired checks that status is unknown.
131
121
if supportsDisconnectedClients && expired {
132
122
result .Lost = append (result .Lost , AllocTuple {
@@ -149,6 +139,7 @@ func diffSystemAllocsForNode(
149
139
continue
150
140
}
151
141
142
+ // note: the node can be both tainted and nil
152
143
node , nodeIsTainted := taintedNodes [exist .NodeID ]
153
144
154
145
// Filter allocs on a node that is now re-connected to reconnecting.
@@ -198,7 +189,7 @@ func diffSystemAllocsForNode(
198
189
continue
199
190
}
200
191
201
- if ! exist . TerminalStatus () && ( node == nil || node .TerminalStatus () ) {
192
+ if node == nil || node .TerminalStatus () {
202
193
result .Lost = append (result .Lost , AllocTuple {
203
194
Name : name ,
204
195
TaskGroup : tg ,
@@ -319,7 +310,7 @@ func materializeSystemTaskGroups(job *structs.Job) map[string]*structs.TaskGroup
319
310
}
320
311
321
312
for _ , tg := range job .TaskGroups {
322
- for i := 0 ; i < tg .Count ; i ++ {
313
+ for i := range tg .Count {
323
314
name := fmt .Sprintf ("%s.%s[%d]" , job .Name , tg .Name , i )
324
315
out [name ] = tg
325
316
}
0 commit comments