Skip to content

Commit 5eb345c

Browse files
style: rename filterBy Tainted
1 parent a763746 commit 5eb345c

4 files changed

Lines changed: 20 additions & 38 deletions

File tree

scheduler/reconciler/filters.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,17 @@ var classificationRules = []classificationRule{
264264
},
265265
}
266266

267-
// filterByTainted takes a set of tainted nodes and filters the allocation set
267+
// classifyAllocs takes a set of tainted nodes and filters the allocation set
268268
// into the following groups:
269-
// 1. Those that exist on untainted nodes
270-
// 2. Those exist on nodes that are draining
271-
// 3. Those that exist on lost nodes or have expired
272-
// 4. Those that are on nodes that are disconnected, but have not had their ClientState set to unknown
273-
// 5. Those that are on a node that has reconnected.
274-
// 6. Those that are in a state that results in a noop.
275-
// 7. Those that are disconnected and need to be marked lost (and possibly replaced)
276-
func (set allocSet) filterByTainted(state ClusterState) (untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring allocSet) {
269+
// 1. untainted: allocs on working nodes, which are in the correct state and don't need to be changed or updated
270+
// 2. migrate: allocs on nodes that are draining or need to be moved
271+
// 3. lost: allocs on lost nodes or have expired and need to be replaced
272+
// 4. disconnect: allocs on nodes that are disconnected, and need to be updated and maybe rescheduled
273+
// 5. reconnecting: allocs on a node that has reconnected and need to go through the reconnect flow
274+
// 6. ignore: allocs in a state that results in a noop that only need to be counted
275+
// 7. expiring: allocs on disconnected nodes and need to be marked lost (and possibly replaced)
276+
277+
func (set allocSet) classifyAllocs(state ClusterState) (untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring allocSet) {
277278
untainted = make(allocSet)
278279
migrate = make(allocSet)
279280
lost = make(allocSet)
@@ -295,7 +296,7 @@ func (set allocSet) filterByTainted(state ClusterState) (untainted, migrate, los
295296

296297
for _, alloc := range set {
297298
// Build context for classification rules.
298-
ctx := allocContext{
299+
allocRuntime := allocContext{
299300
alloc: alloc,
300301
now: state.Now,
301302
}
@@ -304,17 +305,17 @@ func (set allocSet) filterByTainted(state ClusterState) (untainted, migrate, los
304305
if alloc.ClientStatus == structs.AllocClientStatusUnknown ||
305306
alloc.ClientStatus == structs.AllocClientStatusRunning ||
306307
alloc.ClientStatus == structs.AllocClientStatusFailed {
307-
ctx.shouldReconnect = alloc.NeedsToReconnect()
308+
allocRuntime.shouldReconnect = alloc.NeedsToReconnect()
308309
}
309310

310311
// Get node taint information, preserving whether key existed so we can
311312
// distinguish missing-node from GC'd-node semantics.
312-
ctx.taintedNode, ctx.nodeIsTainted = state.TaintedNodes[alloc.NodeID]
313+
allocRuntime.taintedNode, allocRuntime.nodeIsTainted = state.TaintedNodes[alloc.NodeID]
313314

314315
// Apply classification rules in order (first match wins).
315316
classified := false
316317
for _, rule := range classificationRules {
317-
if rule.condition(ctx) {
318+
if rule.condition(allocRuntime) {
318319
targetSet := categoryMap[rule.category]
319320
(*targetSet)[alloc.ID] = alloc
320321
classified = true

scheduler/reconciler/filters_test.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/hashicorp/nomad/helper/pointer"
1110
"github.com/hashicorp/nomad/nomad/mock"
1211
"github.com/hashicorp/nomad/nomad/structs"
1312
"github.com/shoenig/test/must"
@@ -75,7 +74,7 @@ func TestReconciler_filterServerTerminalAllocs(t *testing.T) {
7574
})
7675
}
7776

78-
func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
77+
func TestAllocSet_classifyAllocs_ClassificationRules(t *testing.T) {
7978
now := time.Now()
8079

8180
nodes := map[string]*structs.Node{
@@ -136,30 +135,26 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
136135
a.AllocStates = unknownState
137136
return a
138137
}(),
139-
nodeMap: nodes,
140138
expected: "reconnecting",
141139
},
142140
{
143141
name: "terminal server status ignored",
144142
alloc: makeAlloc("c2", "ready", structs.AllocClientStatusRunning, structs.AllocDesiredStatusStop),
145-
nodeMap: nodes,
146143
expected: "ignore",
147144
},
148145
{
149146
name: "terminal canary migrate",
150147
alloc: func() *structs.Allocation {
151148
a := makeAlloc("c3", "ready", structs.AllocClientStatusComplete, structs.AllocDesiredStatusRun)
152149
a.DeploymentStatus = &structs.AllocDeploymentStatus{Canary: true}
153-
a.DesiredTransition = structs.DesiredTransition{Migrate: new(true)}
150+
a.DesiredTransition = structs.DesiredTransition{Migrate: (true)}
154151
return a
155152
}(),
156-
nodeMap: nodes,
157153
expected: "migrate",
158154
},
159155
{
160156
name: "terminal untainted",
161157
alloc: makeAlloc("c4", "ready", structs.AllocClientStatusComplete, structs.AllocDesiredStatusRun),
162-
nodeMap: nodes,
163158
expected: "untainted",
164159
},
165160
{
@@ -170,7 +165,6 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
170165
a.AllocStates = unknownState
171166
return a
172167
}(),
173-
nodeMap: nodes,
174168
expected: "expiring",
175169
},
176170
{
@@ -180,19 +174,16 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
180174
a.AllocStates = unknownState
181175
return a
182176
}(),
183-
nodeMap: nodes,
184177
expected: "ignore",
185178
},
186179
{
187180
name: "disconnected unknown becomes untainted",
188181
alloc: makeAlloc("c7", "disconnected", structs.AllocClientStatusUnknown, structs.AllocDesiredStatusRun),
189-
nodeMap: nodes,
190182
expected: "untainted",
191183
},
192184
{
193185
name: "disconnected pending lost",
194186
alloc: makeAlloc("c8", "disconnected", structs.AllocClientStatusPending, structs.AllocDesiredStatusRun),
195-
nodeMap: nodes,
196187
expected: "lost",
197188
},
198189
{
@@ -202,23 +193,20 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
202193
a.Job = nil
203194
return a
204195
}(),
205-
nodeMap: nodes,
206196
expected: "lost",
207197
},
208198
{
209199
name: "disconnected grace period",
210200
alloc: makeAlloc("c10", "disconnected", structs.AllocClientStatusRunning, structs.AllocDesiredStatusRun),
211-
nodeMap: nodes,
212201
expected: "disconnecting",
213202
},
214203
{
215204
name: "migrate flag",
216205
alloc: func() *structs.Allocation {
217206
a := makeAlloc("c11", "ready", structs.AllocClientStatusPending, structs.AllocDesiredStatusRun)
218-
a.DesiredTransition = structs.DesiredTransition{Migrate: new(true)}
207+
a.DesiredTransition = structs.DesiredTransition{Migrate: (true)}
219208
return a
220209
}(),
221-
nodeMap: nodes,
222210
expected: "migrate",
223211
},
224212
{
@@ -228,19 +216,16 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
228216
a.AllocStates = unknownState
229217
return a
230218
}(),
231-
nodeMap: nodes,
232219
expected: "reconnecting",
233220
},
234221
{
235222
name: "untainted on non tainted node",
236223
alloc: makeAlloc("c13", "missing", structs.AllocClientStatusRunning, structs.AllocDesiredStatusRun),
237-
nodeMap: nodes,
238224
expected: "untainted",
239225
},
240226
{
241227
name: "gc node lost",
242228
alloc: makeAlloc("c14", "gc", structs.AllocClientStatusRunning, structs.AllocDesiredStatusRun),
243-
nodeMap: nodes,
244229
expected: "lost",
245230
},
246231
{
@@ -250,7 +235,6 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
250235
setDisconnect(a, 5*time.Minute, false)
251236
return a
252237
}(),
253-
nodeMap: nodes,
254238
expected: "untainted",
255239
},
256240
{
@@ -260,19 +244,16 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
260244
setDisconnect(a, 5*time.Minute, false)
261245
return a
262246
}(),
263-
nodeMap: nodes,
264247
expected: "disconnecting",
265248
},
266249
{
267250
name: "terminal node default lost",
268251
alloc: makeAlloc("c17", "down", structs.AllocClientStatusPending, structs.AllocDesiredStatusRun),
269-
nodeMap: nodes,
270252
expected: "lost",
271253
},
272254
{
273255
name: "other tainted node defaults to untainted",
274256
alloc: makeAlloc("c18", "initializing", structs.AllocClientStatusPending, structs.AllocDesiredStatusRun),
275-
nodeMap: nodes,
276257
expected: "untainted",
277258
},
278259
}
@@ -282,7 +263,7 @@ func TestAllocSet_filterByTainted_ClassificationRules(t *testing.T) {
282263
all := allocSet{tc.alloc.ID: tc.alloc}
283264
state := ClusterState{Now: now, TaintedNodes: nodes}
284265

285-
untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring := all.filterByTainted(state)
266+
untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring := all.classifyAllocs(state)
286267

287268
buckets := map[string]allocSet{
288269
"untainted": untainted,

scheduler/reconciler/reconcile_cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func (a *AllocReconciler) computeGroup(group string, all allocSet) (*ReconcileRe
410410
canaries := a.cancelUnneededCanaries(&all, group, result)
411411

412412
// Determine what set of allocations are on tainted nodes
413-
untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring := all.filterByTainted(a.clusterState)
413+
untainted, migrate, lost, disconnecting, reconnecting, ignore, expiring := all.classifyAllocs(a.clusterState)
414414
result.DesiredTGUpdates[group].Ignore += uint64(len(ignore))
415415

416416
// Determine what set of terminal allocations need to be rescheduled

scheduler/reconciler/reconcile_cluster_prop_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func TestAllocReconciler_cancelUnneededCanaries(t *testing.T) {
257257
}
258258
}
259259
canarySet := all.fromKeys(expectedCanaries)
260-
canariesOnUntaintedNodes, migrate, lost, _, _, _, _ := canarySet.filterByTainted(clusterState)
260+
canariesOnUntaintedNodes, migrate, lost, _, _, _, _ := canarySet.classifyAllocs(clusterState)
261261

262262
stopSet = stopSet.union(migrate, lost)
263263

0 commit comments

Comments
 (0)