@@ -32,7 +32,7 @@ func (c *calcium) CreateContainer(specs types.Specs, opts *types.DeployOptions)
32
32
33
33
// when shits go wrong before doCreateContainerWithCPUPeriod, don't just return
34
34
// the channel and return an error, because citadel don't know what's going on
35
- func (c * calcium ) sendErrorMessage (err error , ch chan <- * types.CreateContainerMessage ) {
35
+ func (c * calcium ) createErrorMessage (err error ) * types.CreateContainerMessage {
36
36
log .Errorf ("Got error %s" , err .Error ())
37
37
m := & types.CreateContainerMessage {
38
38
Podname : "" ,
@@ -44,22 +44,21 @@ func (c *calcium) sendErrorMessage(err error, ch chan<- *types.CreateContainerMe
44
44
CPU : nil ,
45
45
Memory : 0 ,
46
46
}
47
- ch <- m
48
- close (ch )
47
+ return m
49
48
}
50
49
51
50
func (c * calcium ) createContainerWithCPUPeriod (specs types.Specs , opts * types.DeployOptions ) (chan * types.CreateContainerMessage , error ) {
52
51
ch := make (chan * types.CreateContainerMessage )
53
52
54
53
if opts .Memory < 4194304 { // 4194304 Byte = 4 MB, docker 创建容器的内存最低标准
55
54
err := fmt .Errorf ("Minimum memory limit allowed is 4MB" )
56
- go c . sendErrorMessage (err , ch )
55
+ ch <- c . createErrorMessage (err )
57
56
return ch , err
58
57
}
59
58
60
59
cpuandmem , _ , err := c .getCPUAndMem (opts .Podname , opts .Nodename , 1.0 )
61
60
if err != nil {
62
- go c . sendErrorMessage (err , ch )
61
+ ch <- c . createErrorMessage (err )
63
62
return ch , err
64
63
}
65
64
nodesInfo := utils .GetNodesInfo (cpuandmem )
@@ -68,7 +67,6 @@ func (c *calcium) createContainerWithCPUPeriod(specs types.Specs, opts *types.De
68
67
plan , err := utils .AllocContainerPlan (nodesInfo , cpuQuota , opts .Memory , opts .Count ) // 还是以 Bytes 作单位, 不转换了
69
68
70
69
if err != nil {
71
- go c .sendErrorMessage (err , ch )
72
70
return ch , err
73
71
}
74
72
0 commit comments