Merge pull request #955 from sameo/topic/delete_container

Handle container creation failures gracefully
This commit is contained in:
Daniel J Walsh 2017-10-06 11:54:10 -04:00 committed by GitHub
commit 19f37f5c14

View file

@ -31,7 +31,7 @@ const (
// ContainerStateStopped represents the stopped state of a container
ContainerStateStopped = "stopped"
// ContainerCreateTimeout represents the value of container creating timeout
ContainerCreateTimeout = 10 * time.Second
ContainerCreateTimeout = 240 * time.Second
// CgroupfsCgroupsManager represents cgroupfs native cgroup manager
CgroupfsCgroupsManager = "cgroupfs"
@ -151,7 +151,7 @@ func getOCIVersion(name string, args ...string) (string, error) {
}
// CreateContainer creates a container.
func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error {
func (r *Runtime) CreateContainer(c *Container, cgroupParent string) (err error) {
var stderrBuf bytes.Buffer
parentPipe, childPipe, err := newPipe()
childStartPipe, parentStartPipe, err := newPipe()
@ -248,6 +248,13 @@ func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error {
return err
}
// We will delete all container resources if creation fails
defer func() {
if err != nil {
r.DeleteContainer(c)
}
}()
// Wait to get container pid from conmon
type syncStruct struct {
si *syncInfo