Delete task on dead shim

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2018-02-06 12:05:35 -05:00
parent 87d15a5ffc
commit 95d4f53fbe
3 changed files with 6 additions and 10 deletions

View File

@ -201,10 +201,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
"id": id, "id": id,
"namespace": namespace, "namespace": namespace,
}).Warn("cleaning up after killed shim") }).Warn("cleaning up after killed shim")
err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid) if err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid); err != nil {
if err == nil {
r.tasks.Delete(ctx, lc)
} else {
log.G(ctx).WithError(err).WithFields(logrus.Fields{ log.G(ctx).WithError(err).WithFields(logrus.Fields{
"id": id, "id": id,
"namespace": namespace, "namespace": namespace,
@ -313,7 +310,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
} }
return nil, errdefs.FromGRPC(err) return nil, errdefs.FromGRPC(err)
} }
r.tasks.Delete(ctx, lc) r.tasks.Delete(ctx, lc.id)
if err := lc.shim.KillShim(ctx); err != nil { if err := lc.shim.KillShim(ctx); err != nil {
log.G(ctx).WithError(err).Error("failed to kill shim") log.G(ctx).WithError(err).Error("failed to kill shim")
} }
@ -443,6 +440,7 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
ExitedAt: exitedAt, ExitedAt: exitedAt,
}) })
r.tasks.Delete(ctx, id)
if err := bundle.Delete(); err != nil { if err := bundle.Delete(); err != nil {
log.G(ctx).WithError(err).Error("delete bundle") log.G(ctx).WithError(err).Error("delete bundle")
} }
@ -458,12 +456,10 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
} }
func (r *Runtime) terminate(ctx context.Context, bundle *bundle, ns, id string) error { func (r *Runtime) terminate(ctx context.Context, bundle *bundle, ns, id string) error {
ctx = namespaces.WithNamespace(ctx, ns)
rt, err := r.getRuntime(ctx, ns, id) rt, err := r.getRuntime(ctx, ns, id)
if err != nil { if err != nil {
return err return err
} }
if err := rt.Delete(ctx, id, &runc.DeleteOpts{ if err := rt.Delete(ctx, id, &runc.DeleteOpts{
Force: true, Force: true,
}); err != nil { }); err != nil {

View File

@ -92,7 +92,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error {
} }
// Delete a task // Delete a task
func (l *TaskList) Delete(ctx context.Context, t Task) { func (l *TaskList) Delete(ctx context.Context, id string) {
l.mu.Lock() l.mu.Lock()
defer l.mu.Unlock() defer l.mu.Unlock()
namespace, err := namespaces.NamespaceRequired(ctx) namespace, err := namespaces.NamespaceRequired(ctx)
@ -101,6 +101,6 @@ func (l *TaskList) Delete(ctx context.Context, t Task) {
} }
tasks, ok := l.tasks[namespace] tasks, ok := l.tasks[namespace]
if ok { if ok {
delete(tasks, t.ID()) delete(tasks, id)
} }
} }

View File

@ -195,7 +195,7 @@ func (r *windowsRuntime) Delete(ctx context.Context, t runtime.Task) (*runtime.E
} }
wt.cleanup() wt.cleanup()
r.tasks.Delete(ctx, t) r.tasks.Delete(ctx, t.ID())
r.publisher.Publish(ctx, r.publisher.Publish(ctx,
runtime.TaskDeleteEventTopic, runtime.TaskDeleteEventTopic,