Skip to content

Commit

Permalink
check exec return code, because docker api will not response error wh…
Browse files Browse the repository at this point in the history
…en use attch
  • Loading branch information
CMGS committed Oct 12, 2017
1 parent 6ecfe15 commit 86e0f66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cluster/calcium/create_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
13 changes: 12 additions & 1 deletion cluster/calcium/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 86e0f66

Please sign in to comment.