Add exited at to events and delete requests
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -120,22 +120,25 @@ func (r *Runtime) Create(ctx context.Context, id string, opts containerd.CreateO
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (uint32, error) {
|
||||
func (r *Runtime) Delete(ctx context.Context, c containerd.Container) (*containerd.Exit, error) {
|
||||
lc, ok := c.(*Container)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("container cannot be cast as *linux.Container")
|
||||
return nil, 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
|
||||
return nil, err
|
||||
}
|
||||
rsp, err := lc.shim.Delete(ctx, &shim.DeleteRequest{})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return nil, err
|
||||
}
|
||||
lc.shim.Exit(ctx, &shim.ExitRequest{})
|
||||
return rsp.ExitStatus, r.deleteBundle(lc.id)
|
||||
return &containerd.Exit{
|
||||
Status: rsp.ExitStatus,
|
||||
Timestamp: rsp.ExitedAt,
|
||||
}, r.deleteBundle(lc.id)
|
||||
}
|
||||
|
||||
func (r *Runtime) Containers(ctx context.Context) ([]containerd.Container, error) {
|
||||
@@ -204,6 +207,7 @@ func (r *Runtime) forward(events shim.Shim_EventsClient) {
|
||||
Pid: e.Pid,
|
||||
ID: e.ID,
|
||||
ExitStatus: e.ExitStatus,
|
||||
ExitedAt: e.ExitedAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
@@ -28,6 +29,7 @@ type execProcess struct {
|
||||
console console.Console
|
||||
io runc.IO
|
||||
status int
|
||||
exited time.Time
|
||||
pid int
|
||||
closers []io.Closer
|
||||
stdin io.Closer
|
||||
@@ -125,8 +127,13 @@ func (e *execProcess) Status() int {
|
||||
return e.status
|
||||
}
|
||||
|
||||
func (e *execProcess) ExitedAt() time.Time {
|
||||
return e.exited
|
||||
}
|
||||
|
||||
func (e *execProcess) Exited(status int) {
|
||||
e.status = status
|
||||
e.exited = time.Now()
|
||||
e.Wait()
|
||||
if e.io != nil {
|
||||
for _, c := range e.closers {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
@@ -28,6 +29,7 @@ type initProcess struct {
|
||||
io runc.IO
|
||||
runc *runc.Runc
|
||||
status int
|
||||
exited time.Time
|
||||
pid int
|
||||
closers []io.Closer
|
||||
stdin io.Closer
|
||||
@@ -121,6 +123,10 @@ func (p *initProcess) Status() int {
|
||||
return p.status
|
||||
}
|
||||
|
||||
func (p *initProcess) ExitedAt() time.Time {
|
||||
return p.exited
|
||||
}
|
||||
|
||||
// ContainerStatus return the state of the container (created, running, paused, stopped)
|
||||
func (p *initProcess) ContainerStatus(ctx context.Context) (string, error) {
|
||||
c, err := p.runc.State(ctx, p.id)
|
||||
@@ -136,6 +142,7 @@ func (p *initProcess) Start(context context.Context) error {
|
||||
|
||||
func (p *initProcess) Exited(status int) {
|
||||
p.status = status
|
||||
p.exited = time.Now()
|
||||
}
|
||||
|
||||
func (p *initProcess) Delete(context context.Context) error {
|
||||
|
||||
@@ -5,6 +5,7 @@ package shim
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/crosbymichael/console"
|
||||
)
|
||||
@@ -18,6 +19,8 @@ type process interface {
|
||||
Exited(status int)
|
||||
// Status returns the exit status
|
||||
Status() int
|
||||
// ExitedAt is the time the process exited
|
||||
ExitedAt() time.Time
|
||||
// Delete deletes the process and its resourcess
|
||||
Delete(context.Context) error
|
||||
// Signal directly signals the process
|
||||
|
||||
@@ -94,6 +94,7 @@ func (s *Service) Delete(ctx context.Context, r *shimapi.DeleteRequest) (*shimap
|
||||
s.mu.Unlock()
|
||||
return &shimapi.DeleteResponse{
|
||||
ExitStatus: uint32(p.Status()),
|
||||
ExitedAt: p.ExitedAt(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -253,5 +254,6 @@ func (s *Service) waitExit(p process, pid int, cmd *reaper.Cmd) {
|
||||
ID: s.id,
|
||||
Pid: uint32(pid),
|
||||
ExitStatus: uint32(status),
|
||||
ExitedAt: p.ExitedAt(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user