From cbe1e57b6b24d4f1f620b6d85371fcfb8d9c3041 Mon Sep 17 00:00:00 2001 From: Zhang Ye Date: Fri, 18 Aug 2017 15:51:04 +0800 Subject: [PATCH] fix the bug found yesterday --- cluster/calcium/create_container.go | 5 +++-- cluster/calcium/realloc.go | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 4ed354914..11779a4fc 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -21,7 +21,8 @@ import ( ) const ( - RESTART_ALWAYS = "always" + RESTART_ALWAYS = "always" + MEMORY_LOW_LIMIT = 4194304 ) // Create Container @@ -41,7 +42,7 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions) func (c *calcium) createContainerWithMemoryPrior(specs types.Specs, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) { ch := make(chan *types.CreateContainerMessage) - if opts.Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 + if opts.Memory < MEMORY_LOW_LIMIT { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准 return ch, fmt.Errorf("Minimum memory limit allowed is 4MB") } if opts.Count <= 0 { // Count 要大于0 diff --git a/cluster/calcium/realloc.go b/cluster/calcium/realloc.go index 675add511..13c870dfc 100644 --- a/cluster/calcium/realloc.go +++ b/cluster/calcium/realloc.go @@ -55,6 +55,7 @@ func (c *calcium) ReallocResource(ids []string, cpu float64, mem int64) (chan *t return nil, fmt.Errorf("[realloc] cpu can not below zero") } if _, ok := podCPUContainersInfo[newCPURequire]; !ok { + podCPUContainersInfo[newCPURequire] = NodeContainers{} // go map 的傻逼语法, 不这样写会有 assignment to entry in nil map 错误 podCPUContainersInfo[newCPURequire][node] = []*types.Container{} } podCPUContainersInfo[newCPURequire][node] = append(podCPUContainersInfo[newCPURequire][node], container) @@ -139,7 +140,7 @@ func (c *calcium) doUpdateContainerWithMemoryPrior( cpuQuota := int64(cpu * float64(utils.CpuPeriodBase)) newCPUQuota := containerJSON.HostConfig.CPUQuota + cpuQuota newMemory := containerJSON.HostConfig.Memory + memory - if newCPUQuota <= 0 || newMemory <= 0 { + if newCPUQuota <= 0 || newMemory <= MEMORY_LOW_LIMIT { log.Warnf("[relloc] new resource invaild %s, %d, %d", containerJSON.ID, newCPUQuota, newMemory) ch <- &types.ReallocResourceMessage{ContainerID: containerJSON.ID, Success: false} continue