Don't delete container with task
Make sure we don't delete a container with a live task Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
22
container.go
22
container.go
@@ -17,8 +17,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoImage = errors.New("container does not have an image")
|
||||
ErrNoRunningTask = errors.New("no running task")
|
||||
ErrNoImage = errors.New("container does not have an image")
|
||||
ErrNoRunningTask = errors.New("no running task")
|
||||
ErrDeleteRunningTask = errors.New("cannot delete container with running task")
|
||||
)
|
||||
|
||||
type Container interface {
|
||||
@@ -45,7 +46,6 @@ type container struct {
|
||||
|
||||
client *Client
|
||||
c containers.Container
|
||||
task *task
|
||||
}
|
||||
|
||||
// ID returns the container's unique id
|
||||
@@ -69,6 +69,9 @@ func (c *container) Spec() (*specs.Spec, error) {
|
||||
// Delete deletes an existing container
|
||||
// an error is returned if the container has running tasks
|
||||
func (c *container) Delete(ctx context.Context) (err error) {
|
||||
if _, err := c.Task(ctx, nil); err == nil {
|
||||
return ErrDeleteRunningTask
|
||||
}
|
||||
// TODO: should the client be the one removing resources attached
|
||||
// to the container at the moment before we have GC?
|
||||
if c.c.RootFS != "" {
|
||||
@@ -83,16 +86,7 @@ func (c *container) Delete(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
func (c *container) Task(ctx context.Context, attach IOAttach) (Task, error) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.task == nil {
|
||||
t, err := c.loadTask(ctx, attach)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.task = t.(*task)
|
||||
}
|
||||
return c.task, nil
|
||||
return c.loadTask(ctx, attach)
|
||||
}
|
||||
|
||||
// Image returns the image that the container is based on
|
||||
@@ -163,7 +157,6 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation, opts ...Ne
|
||||
t.pid = response.Pid
|
||||
close(t.pidSync)
|
||||
}
|
||||
c.task = t
|
||||
return t, nil
|
||||
}
|
||||
|
||||
@@ -206,7 +199,6 @@ func (c *container) loadTask(ctx context.Context, ioAttach IOAttach) (Task, erro
|
||||
pid: response.Task.Pid,
|
||||
pidSync: ps,
|
||||
}
|
||||
c.task = t
|
||||
return t, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user