Skip to content

Commit ac7b94b

Browse files
author
zhangye
committed
Merge branch 'dev' into 'master'
fix bug: 创建内存为0的容器的时候会崩溃 在 `createContainerWithCPUPeriod()` 中加了一段参数检查,如果 memory 小于4MB, 就抛出 error See merge request !20
2 parents 960b20c + 4b6e897 commit ac7b94b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cluster/calcium/create_container.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions)
3333
func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
3434
ch := make(chan *types.CreateContainerMessage)
3535

36+
if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
37+
return ch, fmt.Errorf("Minimum memory limit allowed is 4MB")
38+
}
39+
3640
cpuandmem, _, err := c.getCPUAndMem(opts.Podname, opts.Nodename, 1.0)
3741
if err != nil {
3842
return ch, err
3943
}
4044
nodesInfo := utils.GetNodesInfo(cpuandmem)
4145

4246
cpuQuota := int(opts.CPUQuota * float64(utils.CpuPeriodBase))
43-
// memory := opts.Memory / 1024 / 1024 // 转换成MB
4447
plan, err := utils.AllocContainerPlan(nodesInfo, cpuQuota, opts.Memory, opts.Count) // 还是以 Bytes 作单位, 不转换了
4548

4649
if err != nil {

0 commit comments

Comments
 (0)