Skip to content

Commit

Permalink
check cpu suffience when realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwinger233 committed Jul 30, 2020
1 parent a9d896f commit b8094bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (c *Calcium) doReallocContainer(ctx context.Context, ch chan *types.Realloc
}
// 得到最终方案
cpusets = nodeCPUPlans[node.Name][:containerWithCPUBind]
} else if newCPU != 0 { // nolint
if cap := float64(len(node.InitCPU)) / newCPU; int(cap) < len(containers) {
return types.NewDetailedErr(types.ErrInsufficientCPU, node.Name)
}
}

newResource := &enginetypes.VirtualizationResource{
Expand Down
3 changes: 3 additions & 0 deletions cluster/calcium/realloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestRealloc(t *testing.T) {
Name: "node1",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
Engine: engine,
Endpoint: "http://1.1.1.1:1",
NUMA: types.NUMA{"2": "0"},
Expand Down Expand Up @@ -210,6 +211,7 @@ func TestRealloc(t *testing.T) {
Name: "node2",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
Engine: engine,
Endpoint: "http://1.1.1.1:1",
NUMA: types.NUMA{"2": "0"},
Expand Down Expand Up @@ -445,6 +447,7 @@ func TestReallocBindCpu(t *testing.T) {
Name: "node3",
MemCap: int64(units.GiB),
CPU: types.CPUMap{"0": 10, "1": 70, "2": 10, "3": 100},
InitCPU: types.CPUMap{"0": 100, "1": 100, "2": 100, "3": 100},
CPUUsed: 2.1,
Engine: engine,
Endpoint: "http://1.1.1.1:1",
Expand Down

0 comments on commit b8094bb

Please sign in to comment.