Skip to content

Commit b8094bb

Browse files
committed
check cpu suffience when realloc
1 parent a9d896f commit b8094bb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cluster/calcium/realloc.go

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func (c *Calcium) doReallocContainer(ctx context.Context, ch chan *types.Realloc
138138
}
139139
// 得到最终方案
140140
cpusets = nodeCPUPlans[node.Name][:containerWithCPUBind]
141+
} else if newCPU != 0 { // nolint
142+
if cap := float64(len(node.InitCPU)) / newCPU; int(cap) < len(containers) {
143+
return types.NewDetailedErr(types.ErrInsufficientCPU, node.Name)
144+
}
141145
}
142146

143147
newResource := &enginetypes.VirtualizationResource{

cluster/calcium/realloc_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestRealloc(t *testing.T) {
5050
Name: "node1",
5151
MemCap: int64(units.GiB),
5252
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
53+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
5354
Engine: engine,
5455
Endpoint: "http://1.1.1.1:1",
5556
NUMA: types.NUMA{"2": "0"},
@@ -210,6 +211,7 @@ func TestRealloc(t *testing.T) {
210211
Name: "node2",
211212
MemCap: int64(units.GiB),
212213
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
214+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
213215
Engine: engine,
214216
Endpoint: "http://1.1.1.1:1",
215217
NUMA: types.NUMA{"2": "0"},
@@ -445,6 +447,7 @@ func TestReallocBindCpu(t *testing.T) {
445447
Name: "node3",
446448
MemCap: int64(units.GiB),
447449
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
450+
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
448451
CPUUsed: 2.1,
449452
Engine: engine,
450453
Endpoint: "http://1.1.1.1:1",

0 commit comments

Comments
 (0)