Add container to monitor in runtime

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-03-21 13:08:49 -07:00
parent f36feb2ed4
commit 155185c2b2
4 changed files with 30 additions and 4 deletions

View file

@ -54,6 +54,7 @@ func New(ic *plugin.InitContext) (interface{}, error) {
events: make(chan *containerd.Event, 2048),
eventsContext: c,
eventsCancel: cancel,
monitor: ic.Monitor,
}, nil
}
@ -64,6 +65,7 @@ type Runtime struct {
events chan *containerd.Event
eventsContext context.Context
eventsCancel func()
monitor plugin.ContainerMonitor
}
func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateOpts) (containerd.Container, error) {
@ -100,10 +102,15 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
os.RemoveAll(path)
return nil, err
}
return &Container{
c := &Container{
id: id,
shim: s,
}, nil
}
// after the container is create add it to the monitor
if err := r.monitor.Monitor(c); err != nil {
return nil, err
}
return c, nil
}
func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (uint32, error) {
@ -111,6 +118,11 @@ func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (uint32, e
if !ok {
return 0, fmt.Errorf("container cannot be cast as *linux.Container")
}
// remove the container from the monitor
if err := r.monitor.Stop(lc); err != nil {
// TODO: log error here
return 0, err
}
rsp, err := lc.shim.Delete(ctx, &shim.DeleteRequest{})
if err != nil {
return 0, err