@@ -27,6 +27,16 @@ func (c *Calcium) CreateContainer(ctx context.Context, opts *types.DeployOptions
27
27
return nil , err
28
28
}
29
29
log .Infof ("[CreateContainer] Creating container with options: %v" , opts )
30
+
31
+ // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
32
+ // -1 means without limit
33
+ if opts .Memory < minMemory && ! opts .RawResource {
34
+ return nil , fmt .Errorf ("Minimum memory limit allowed is 4MB, got %d" , opts .Memory )
35
+ }
36
+ if opts .Count <= 0 { // Count 要大于0
37
+ return nil , fmt .Errorf ("Count must be positive, got %d" , opts .Count )
38
+ }
39
+
30
40
if opts .RawResource || pod .Favor == scheduler .MEMORY_PRIOR {
31
41
return c .createContainerWithMemoryPrior (ctx , opts )
32
42
} else if pod .Favor == scheduler .CPU_PRIOR {
@@ -37,14 +47,6 @@ func (c *Calcium) CreateContainer(ctx context.Context, opts *types.DeployOptions
37
47
38
48
func (c * Calcium ) createContainerWithMemoryPrior (ctx context.Context , opts * types.DeployOptions ) (chan * types.CreateContainerMessage , error ) {
39
49
ch := make (chan * types.CreateContainerMessage )
40
- // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
41
- // -1 means without limit
42
- if opts .Memory < minMemory && ! opts .RawResource {
43
- return ch , fmt .Errorf ("Minimum memory limit allowed is 4MB, got %d" , opts .Memory )
44
- }
45
- if opts .Count <= 0 { // Count 要大于0
46
- return ch , fmt .Errorf ("Count must be positive, got %d" , opts .Count )
47
- }
48
50
49
51
// TODO RFC 计算当前 app 部署情况的时候需要保证同一时间只有这个 app 的这个 entrypoint 在跑
50
52
// 因此需要在这里加个全局锁,直到部署完毕才释放
@@ -87,7 +89,7 @@ func (c *Calcium) doCreateContainerWithMemoryPrior(ctx context.Context, nodeInfo
87
89
for i := 0 ; i < nodeInfo .Deploy ; i ++ {
88
90
ms [i ] = & types.CreateContainerMessage {Error : err }
89
91
if ! opts .RawResource {
90
- if err := c .store .UpdateNodeMem (ctx , opts .Podname , nodeInfo .Name , opts .Memory , "+" ); err != nil {
92
+ if err := c .store .UpdateNodeResource (ctx , opts .Podname , nodeInfo .Name , types. CPUMap {} , opts .Memory , "+" ); err != nil {
91
93
log .Errorf ("[doCreateContainerWithMemoryPrior] reset node memory failed %v" , err )
92
94
}
93
95
}
@@ -153,7 +155,7 @@ func (c *Calcium) doCreateContainerWithCPUPrior(ctx context.Context, nodeName st
153
155
log .Errorf ("[doCreateContainerWithCPUPrior] Get and prepare node error %v" , err )
154
156
for i := 0 ; i < deployCount ; i ++ {
155
157
ms [i ] = & types.CreateContainerMessage {Error : err }
156
- if err := c .store .UpdateNodeCPU (ctx , opts .Podname , nodeName , cpuMap [i ], "+" ); err != nil {
158
+ if err := c .store .UpdateNodeResource (ctx , opts .Podname , nodeName , cpuMap [i ], opts . Memory , "+" ); err != nil {
157
159
log .Errorf ("[doCreateContainerWithCPUPrior] update node CPU failed %v" , err )
158
160
}
159
161
}
@@ -296,7 +298,7 @@ func (c *Calcium) makeContainerOptions(index int, quota types.CPUMap, opts *type
296
298
297
299
var resource enginecontainer.Resources
298
300
if favor == scheduler .CPU_PRIOR {
299
- resource = makeCPUPriorSetting (c .config .Scheduler .ShareBase , quota )
301
+ resource = makeCPUPriorSetting (c .config .Scheduler .ShareBase , quota , opts . Memory )
300
302
} else if favor == scheduler .MEMORY_PRIOR {
301
303
resource = makeMemoryPriorSetting (opts .Memory , opts .CPUQuota )
302
304
} else {
0 commit comments