From 37855aff121a7cf9deae0405910a62518e806a9e Mon Sep 17 00:00:00 2001 From: Travis DePrato Date: Sun, 10 Jan 2021 22:52:15 -0800 Subject: Add support for pause/restore in containerd shim --- pkg/shim/runsc/runsc.go | 14 ++++++++++++++ pkg/shim/service.go | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'pkg/shim') diff --git a/pkg/shim/runsc/runsc.go b/pkg/shim/runsc/runsc.go index aedaf5ee5..e1d616d6f 100644 --- a/pkg/shim/runsc/runsc.go +++ b/pkg/shim/runsc/runsc.go @@ -167,6 +167,20 @@ func (r *Runsc) Create(context context.Context, id, bundle string, opts *CreateO return err } +func (r *Runsc) Pause(context context.Context, id string) error { + if _, err := cmdOutput(r.command(context, "pause", id), true); err != nil { + return fmt.Errorf("unable to pause: %s", err) + } + return nil +} + +func (r *Runsc) Resume(context context.Context, id string) error { + if _, err := cmdOutput(r.command(context, "pause", id), true); err != nil { + return fmt.Errorf("unable to resume: %s", err) + } + return nil +} + // Start will start an already created container. func (r *Runsc) Start(context context.Context, id string, cio runc.IO) error { cmd := r.command(context, "start", id) diff --git a/pkg/shim/service.go b/pkg/shim/service.go index 9aba26ac7..844210abb 100644 --- a/pkg/shim/service.go +++ b/pkg/shim/service.go @@ -612,13 +612,15 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI. // Pause the container. func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*types.Empty, error) { log.L.Debugf("Pause, id: %s", r.ID) - return empty, errdefs.ToGRPC(errdefs.ErrNotImplemented) + err := s.task.Runtime().Pause(ctx, r.ID) + return empty, err } // Resume the container. func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*types.Empty, error) { log.L.Debugf("Resume, id: %s", r.ID) - return empty, errdefs.ToGRPC(errdefs.ErrNotImplemented) + err := s.task.Runtime().Resume(ctx, r.ID) + return empty, err } // Kill a process with the provided signal. -- cgit v1.2.3 From a88d6caf533e11d3171232e415f106475e5b3f08 Mon Sep 17 00:00:00 2001 From: Travis DePrato Date: Wed, 13 Jan 2021 13:04:50 -0800 Subject: Fix code review issues --- pkg/shim/runsc/runsc.go | 6 +++--- pkg/shim/service.go | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'pkg/shim') diff --git a/pkg/shim/runsc/runsc.go b/pkg/shim/runsc/runsc.go index e1d616d6f..3c4cbf223 100644 --- a/pkg/shim/runsc/runsc.go +++ b/pkg/shim/runsc/runsc.go @@ -169,14 +169,14 @@ func (r *Runsc) Create(context context.Context, id, bundle string, opts *CreateO func (r *Runsc) Pause(context context.Context, id string) error { if _, err := cmdOutput(r.command(context, "pause", id), true); err != nil { - return fmt.Errorf("unable to pause: %s", err) + return fmt.Errorf("unable to pause: %w", err) } return nil } func (r *Runsc) Resume(context context.Context, id string) error { - if _, err := cmdOutput(r.command(context, "pause", id), true); err != nil { - return fmt.Errorf("unable to resume: %s", err) + if _, err := cmdOutput(r.command(context, "resume", id), true); err != nil { + return fmt.Errorf("unable to resume: %w", err) } return nil } diff --git a/pkg/shim/service.go b/pkg/shim/service.go index 844210abb..eff55df53 100644 --- a/pkg/shim/service.go +++ b/pkg/shim/service.go @@ -612,15 +612,29 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI. // Pause the container. func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*types.Empty, error) { log.L.Debugf("Pause, id: %s", r.ID) + if s.task == nil { + log.L.Debugf("Pause error, id: %s: container not created", r.ID) + return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created") + } err := s.task.Runtime().Pause(ctx, r.ID) - return empty, err + if err != nil { + return nil, err + } + return empty, nil } // Resume the container. func (s *service) Resume(ctx context.Context, r *taskAPI.ResumeRequest) (*types.Empty, error) { log.L.Debugf("Resume, id: %s", r.ID) + if s.task == nil { + log.L.Debugf("Resume error, id: %s: container not created", r.ID) + return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created") + } err := s.task.Runtime().Resume(ctx, r.ID) - return empty, err + if err != nil { + return nil, err + } + return empty, nil } // Kill a process with the provided signal. -- cgit v1.2.3