Skip to content

Commit

Permalink
Merge branch 'bug-fix' into 'master'
Browse files Browse the repository at this point in the history
fix the bug found yesterday

See merge request !137
  • Loading branch information
CMGS committed Aug 18, 2017
2 parents e8bc5f5 + cbe1e57 commit 9574101
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

const (
RESTART_ALWAYS = "always"
RESTART_ALWAYS = "always"
MEMORY_LOW_LIMIT = 4194304
)

// Create Container
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cluster/calcium/realloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9574101

Please sign in to comment.