Skip to content

Commit 9c66203

Browse files
committed
system scheduler: fixes to computeJobAllocs
1 parent c8d7a9a commit 9c66203

File tree

6 files changed

+137
-166
lines changed

6 files changed

+137
-166
lines changed

nomad/mock/alloc.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ func Alloc() *structs.Allocation {
2424
CPU: 500,
2525
MemoryMB: 256,
2626
DiskMB: 150,
27-
// Networks: []*structs.NetworkResource{
28-
// {
29-
// Device: "eth0",
30-
// IP: "192.168.0.100",
31-
// ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
32-
// MBits: 50,
33-
// DynamicPorts: []structs.Port{{Label: "http"}},
34-
// },
35-
// },
27+
Networks: []*structs.NetworkResource{
28+
{
29+
Device: "eth0",
30+
IP: "192.168.0.100",
31+
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
32+
MBits: 50,
33+
DynamicPorts: []structs.Port{{Label: "http"}},
34+
},
35+
},
3636
},
3737
TaskResources: map[string]*structs.Resources{
3838
"web": {
3939
CPU: 500,
4040
MemoryMB: 256,
41-
// Networks: []*structs.NetworkResource{
42-
// {
43-
// Device: "eth0",
44-
// IP: "192.168.0.100",
45-
// ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
46-
// MBits: 50,
47-
// DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
48-
// },
49-
// },
41+
Networks: []*structs.NetworkResource{
42+
{
43+
Device: "eth0",
44+
IP: "192.168.0.100",
45+
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
46+
MBits: 50,
47+
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
48+
},
49+
},
5050
},
5151
},
5252
SharedResources: &structs.Resources{
@@ -62,15 +62,15 @@ func Alloc() *structs.Allocation {
6262
Memory: structs.AllocatedMemoryResources{
6363
MemoryMB: 256,
6464
},
65-
// Networks: []*structs.NetworkResource{
66-
// {
67-
// Device: "eth0",
68-
// IP: "192.168.0.100",
69-
// ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
70-
// MBits: 50,
71-
// DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
72-
// },
73-
// },
65+
Networks: []*structs.NetworkResource{
66+
{
67+
Device: "eth0",
68+
IP: "192.168.0.100",
69+
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
70+
MBits: 50,
71+
DynamicPorts: []structs.Port{{Label: "http", Value: 9876}},
72+
},
73+
},
7474
},
7575
},
7676
Shared: structs.AllocatedSharedResources{
@@ -131,22 +131,22 @@ func AllocWithoutReservedPort() *structs.Allocation {
131131
}
132132

133133
func AllocForNode(n *structs.Node) *structs.Allocation {
134-
// nodeIP := n.NodeResources.NodeNetworks[0].Addresses[0].Address
134+
nodeIP := n.NodeResources.NodeNetworks[0].Addresses[0].Address
135135

136-
// dynamicPortRange := structs.DefaultMaxDynamicPort - structs.DefaultMinDynamicPort
137-
// randomDynamicPort := rand.Intn(dynamicPortRange) + structs.DefaultMinDynamicPort
136+
dynamicPortRange := structs.DefaultMaxDynamicPort - structs.DefaultMinDynamicPort
137+
randomDynamicPort := rand.Intn(dynamicPortRange) + structs.DefaultMinDynamicPort
138138

139139
alloc := Alloc()
140140
alloc.NodeID = n.ID
141141

142142
// Set node IP address.
143-
// alloc.Resources.Networks[0].IP = nodeIP
144-
// alloc.TaskResources["web"].Networks[0].IP = nodeIP
145-
// alloc.AllocatedResources.Tasks["web"].Networks[0].IP = nodeIP
143+
alloc.Resources.Networks[0].IP = nodeIP
144+
alloc.TaskResources["web"].Networks[0].IP = nodeIP
145+
alloc.AllocatedResources.Tasks["web"].Networks[0].IP = nodeIP
146146

147147
// Set dynamic port to a random value.
148-
// alloc.TaskResources["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
149-
// alloc.AllocatedResources.Tasks["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
148+
alloc.TaskResources["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
149+
alloc.AllocatedResources.Tasks["web"].Networks[0].DynamicPorts = []structs.Port{{Label: "http", Value: randomDynamicPort}}
150150

151151
return alloc
152152

nomad/mock/job.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,12 @@ func SystemJob() *structs.Job {
474474
Resources: &structs.Resources{
475475
CPU: 500,
476476
MemoryMB: 256,
477-
// Networks: []*structs.NetworkResource{
478-
// {
479-
// MBits: 50,
480-
// DynamicPorts: []structs.Port{{Label: "http"}},
481-
// },
482-
// },
477+
Networks: []*structs.NetworkResource{
478+
{
479+
MBits: 50,
480+
DynamicPorts: []structs.Port{{Label: "http"}},
481+
},
482+
},
483483
},
484484
LogConfig: structs.DefaultLogConfig(),
485485
},

scheduler/reconciler/reconcile_node_prop_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestNodeReconciler_PropTest(t *testing.T) {
101101
nr := genNodeReconciler(structs.JobTypeSystem, &idGenerator{}).Draw(t, "input")
102102
n := NewNodeReconciler(nr.deployment)
103103
results := n.Compute(nr.job, nr.readyNodes,
104-
nr.notReadyNodes, nr.taintedNodes, nil, nr.allocs, nr.terminal,
104+
nr.notReadyNodes, nr.taintedNodes, nr.allocs, nr.terminal,
105105
nr.serverSupportsDisconnectedClients)
106106
must.NotNil(t, results, must.Sprint("results should never be nil"))
107107
perTaskGroup := collectExpectedAndResults(nr, results)
@@ -113,7 +113,7 @@ func TestNodeReconciler_PropTest(t *testing.T) {
113113
nr := genNodeReconciler(structs.JobTypeSysBatch, &idGenerator{}).Draw(t, "input")
114114
n := NewNodeReconciler(nr.deployment)
115115
results := n.Compute(nr.job, nr.readyNodes,
116-
nr.notReadyNodes, nr.taintedNodes, nil, nr.allocs, nr.terminal,
116+
nr.notReadyNodes, nr.taintedNodes, nr.allocs, nr.terminal,
117117
nr.serverSupportsDisconnectedClients)
118118
must.NotNil(t, results, must.Sprint("results should never be nil"))
119119
perTaskGroup := collectExpectedAndResults(nr, results)

scheduler/reconciler/reconcile_node_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestDiffSystemAllocsForNode_Sysbatch_terminal(t *testing.T) {
7373
}
7474

7575
nr := NewNodeReconciler(nil)
76-
diff := nr.computeForNode(job, "node1", eligible, nil, tainted, nil, required, live, terminal, true)
76+
diff := nr.computeForNode(job, "node1", eligible, nil, tainted, required, live, terminal, true)
7777

7878
assertDiffCount(t, diffResultCount{ignore: 1, place: 1}, diff)
7979
if len(diff.Ignore) > 0 {
@@ -96,7 +96,7 @@ func TestDiffSystemAllocsForNode_Sysbatch_terminal(t *testing.T) {
9696
}
9797

9898
nr := NewNodeReconciler(nil)
99-
diff := nr.computeForNode(job, "node1", eligible, nil, tainted, nil, required, live, terminal, true)
99+
diff := nr.computeForNode(job, "node1", eligible, nil, tainted, required, live, terminal, true)
100100
assertDiffCount(t, diffResultCount{update: 1, place: 1}, diff)
101101
})
102102

@@ -160,7 +160,7 @@ func TestDiffSystemAllocsForNode_Placements(t *testing.T) {
160160
nr := NewNodeReconciler(nil)
161161
diff := nr.computeForNode(
162162
job, tc.nodeID, eligible, nil,
163-
tainted, nil, required, allocsForNode, terminal, true)
163+
tainted, required, allocsForNode, terminal, true)
164164

165165
assertDiffCount(t, tc.expected, diff)
166166
})
@@ -218,7 +218,7 @@ func TestDiffSystemAllocsForNode_Stops(t *testing.T) {
218218

219219
nr := NewNodeReconciler(nil)
220220
diff := nr.computeForNode(
221-
job, node.ID, eligible, nil, tainted, nil, required, allocs, terminal, true)
221+
job, node.ID, eligible, nil, tainted, required, allocs, terminal, true)
222222

223223
assertDiffCount(t, diffResultCount{ignore: 1, stop: 1, update: 1}, diff)
224224
if len(diff.Update) > 0 {
@@ -288,7 +288,7 @@ func TestDiffSystemAllocsForNode_IneligibleNode(t *testing.T) {
288288

289289
nr := NewNodeReconciler(nil)
290290
diff := nr.computeForNode(
291-
job, tc.nodeID, eligible, ineligible, tainted, nil,
291+
job, tc.nodeID, eligible, ineligible, tainted,
292292
required, []*structs.Allocation{alloc}, terminal, true,
293293
)
294294
assertDiffCount(t, tc.expect, diff)
@@ -346,7 +346,7 @@ func TestDiffSystemAllocsForNode_DrainingNode(t *testing.T) {
346346
nr := NewNodeReconciler(nil)
347347
diff := nr.computeForNode(
348348
job, drainNode.ID, map[string]*structs.Node{}, nil,
349-
tainted, nil, required, allocs, terminal, true)
349+
tainted, required, allocs, terminal, true)
350350

351351
assertDiffCount(t, diffResultCount{migrate: 1, ignore: 1}, diff)
352352
if len(diff.Migrate) > 0 {
@@ -398,7 +398,7 @@ func TestDiffSystemAllocsForNode_LostNode(t *testing.T) {
398398
nr := NewNodeReconciler(nil)
399399
diff := nr.computeForNode(
400400
job, deadNode.ID, map[string]*structs.Node{}, nil,
401-
tainted, nil, required, allocs, terminal, true)
401+
tainted, required, allocs, terminal, true)
402402

403403
assertDiffCount(t, diffResultCount{lost: 2}, diff)
404404
if len(diff.Migrate) > 0 {
@@ -523,7 +523,7 @@ func TestDiffSystemAllocsForNode_DisconnectedNode(t *testing.T) {
523523

524524
nr := NewNodeReconciler(nil)
525525
got := nr.computeForNode(
526-
job, tc.node.ID, eligibleNodes, nil, taintedNodes, nil,
526+
job, tc.node.ID, eligibleNodes, nil, taintedNodes,
527527
required, []*structs.Allocation{alloc}, terminal, true,
528528
)
529529
assertDiffCount(t, tc.expect, got)
@@ -611,7 +611,7 @@ func TestDiffSystemAllocs(t *testing.T) {
611611
}
612612

613613
nr := NewNodeReconciler(nil)
614-
diff := nr.Compute(job, nodes, nil, tainted, nil, allocs, terminal, true)
614+
diff := nr.Compute(job, nodes, nil, tainted, allocs, terminal, true)
615615
assertDiffCount(t, diffResultCount{
616616
update: 1, ignore: 1, migrate: 1, lost: 1, place: 6}, diff)
617617

@@ -766,7 +766,7 @@ func TestNodeDeployments(t *testing.T) {
766766
for _, tc := range testCases {
767767
t.Run(tc.name, func(t *testing.T) {
768768
nr := NewNodeReconciler(tc.existingDeployment)
769-
nr.Compute(tc.job, nodes, nil, nil, nil, tc.liveAllocs, tc.terminalAllocs, true)
769+
nr.Compute(tc.job, nodes, nil, nil, tc.liveAllocs, tc.terminalAllocs, true)
770770
if tc.newDeployment {
771771
must.NotNil(t, nr.DeploymentCurrent, must.Sprintf("expected a non-nil deployment"))
772772
must.Eq(t, nr.DeploymentCurrent.Status, tc.expectedNewDeploymentStatus)

0 commit comments

Comments
 (0)