diff --git a/cluster/calcium/create_container.go b/cluster/calcium/create_container.go index 49f735ac1..0ee717645 100644 --- a/cluster/calcium/create_container.go +++ b/cluster/calcium/create_container.go @@ -98,7 +98,7 @@ func (c *calcium) doCreateContainerWithMemoryPrior(nodeInfo types.NodeInfo, opts c.store.UpdateNodeMem(opts.Podname, nodeInfo.Name, opts.Memory, "+") // 创建容器失败就要把资源还回去对不对? // clean up if ms[i].ContainerID != "" { - if err := node.Engine.ContainerRemove(context.Background(), ms[i].ContainerID, enginetypes.ContainerRemoveOptions{}); err != nil { + if err := node.Engine.ContainerRemove(context.Background(), ms[i].ContainerID, enginetypes.ContainerRemoveOptions{Force: true}); err != nil { log.Errorf("[doCreateContainerWithMemoryPrior] Error during remove failed container %v", err) } } @@ -177,7 +177,7 @@ func (c *calcium) doCreateContainerWithCPUPrior(nodeName string, cpuMap []types. } // clean up if ms[i].ContainerID != "" { - if err := node.Engine.ContainerRemove(context.Background(), ms[i].ContainerID, enginetypes.ContainerRemoveOptions{}); err != nil { + if err := node.Engine.ContainerRemove(context.Background(), ms[i].ContainerID, enginetypes.ContainerRemoveOptions{Force: true}); err != nil { log.Errorf("[doCreateContainerWithCPUPrior] Error during remove failed container %v", err) } } diff --git a/cluster/calcium/helper.go b/cluster/calcium/helper.go index 364396f58..a112c0000 100644 --- a/cluster/calcium/helper.go +++ b/cluster/calcium/helper.go @@ -206,5 +206,16 @@ func execuateInside(client *engineapi.Client, ID, cmd, user string, env []string } defer resp.Close() stream := utils.FuckDockerStream(ioutil.NopCloser(resp.Reader)) - return ioutil.ReadAll(stream) + b, err := ioutil.ReadAll(stream) + if err != nil { + return []byte{}, err + } + info, err := client.ContainerExecInspect(context.Background(), idResp.ID) + if err != nil { + return []byte{}, err + } + if info.ExitCode != 0 { + return []byte{}, fmt.Errorf("%s", b) + } + return b, nil }