Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
containerd-shim-kata-v2: add the service Pause support
Browse files Browse the repository at this point in the history
Add the Pause api support to pause a container running
in the pod.

Signed-off-by: ZeroMagic <[email protected]>
  • Loading branch information
ZeroMagic authored and lifupan committed Nov 28, 2018
1 parent cd321a3 commit 8df33d3
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,28 @@ func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.

// Pause the container
func (s *service) Pause(ctx context.Context, r *taskAPI.PauseRequest) (*ptypes.Empty, error) {
return nil, errdefs.ErrNotImplemented
s.Lock()
defer s.Unlock()

c, err := s.getContainer(r.ID)
if err != nil {
return nil, err
}

c.status = task.StatusPausing

err = s.sandbox.PauseContainer(r.ID)
if err == nil {
c.status = task.StatusPaused
return empty, nil
}

c.status, err = s.getContainerStatus(c.id)
if err != nil {
c.status = task.StatusUnknown
}

return empty, err
}

// Resume the container
Expand Down Expand Up @@ -678,3 +699,24 @@ func (s *service) getContainer(id string) (*container, error) {

return c, nil
}

func (s *service) getContainerStatus(containerID string) (task.Status, error) {
cStatus, err := s.sandbox.StatusContainer(containerID)
if err != nil {
return task.StatusUnknown, err
}

var status task.Status
switch cStatus.State.State {
case vc.StateReady:
status = task.StatusCreated
case vc.StateRunning:
status = task.StatusRunning
case vc.StatePaused:
status = task.StatusPaused
case vc.StateStopped:
status = task.StatusStopped
}

return status, nil
}

0 comments on commit 8df33d3

Please sign in to comment.