diff --git a/cluster/calcium/realloc.go b/cluster/calcium/realloc.go index f7fde78c2..286549bcb 100644 --- a/cluster/calcium/realloc.go +++ b/cluster/calcium/realloc.go @@ -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(node.InitCPU.Total()) / float64(c.config.Scheduler.ShareBase) / newCPU; int(cap) < len(containers) { // nolint + return types.NewDetailedErr(types.ErrInsufficientCPU, node.Name) + } } newResource := &enginetypes.VirtualizationResource{ diff --git a/cluster/calcium/realloc_test.go b/cluster/calcium/realloc_test.go index ce0926475..6ce9586cf 100644 --- a/cluster/calcium/realloc_test.go +++ b/cluster/calcium/realloc_test.go @@ -34,6 +34,7 @@ func TestRealloc(t *testing.T) { ctx := context.Background() store := &storemocks.Store{} c.store = store + c.config.Scheduler.ShareBase = 100 lock := &lockmocks.DistributedLock{} lock.On("Lock", mock.Anything).Return(nil) @@ -50,6 +51,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"}, @@ -210,6 +212,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"}, @@ -406,6 +409,7 @@ func TestReallocVolume(t *testing.T) { func TestReallocBindCpu(t *testing.T) { c := NewTestCluster() + c.config.Scheduler.ShareBase = 100 ctx := context.Background() store := &storemocks.Store{} c.store = store @@ -445,6 +449,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", diff --git a/scheduler/complex/potassium.go b/scheduler/complex/potassium.go index c3b86dea2..052d771bf 100644 --- a/scheduler/complex/potassium.go +++ b/scheduler/complex/potassium.go @@ -80,7 +80,9 @@ func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64, // 筛选出能满足 CPU 需求的 sort.Slice(nodesInfo, func(i, j int) bool { return len(nodesInfo[i].CPUMap) < len(nodesInfo[j].CPUMap) }) - p := sort.Search(nodesInfoLength, func(i int) bool { return float64(len(nodesInfo[i].CPUMap)) >= quota }) + p := sort.Search(nodesInfoLength, func(i int) bool { + return float64(len(nodesInfo[i].CPUMap)) >= quota + }) // p 最大也就是 nodesInfoLength - 1 if p == nodesInfoLength { return nil, 0, types.ErrInsufficientCPU