Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pkg/shim/v1/runsc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,23 @@ func (s *runscService) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (

// Checkpoint checkpoints the container.
func (s *runscService) Checkpoint(ctx context.Context, r *taskAPI.CheckpointTaskRequest) (*types.Empty, error) {
return empty, errdefs.ErrNotImplemented
if s.task == nil {
log.L.Debugf("Checkpoint error, id: %s: container not created", r.ID)
return nil, errdefs.ToGRPCf(errdefs.ErrFailedPrecondition, "container must be created")
}

opts := &runsccmd.CheckpointOpts{
ImagePath: r.Path,
}

err := s.task.Runtime().Checkpoint(ctx, r.ID, opts)
if err != nil {
log.L.Debugf("Checkpoint failed: %v", err)

return nil, err
}
log.L.Debugf("Checkpoint succeeded")
return empty, nil
}

// Restore restores the container.
Expand Down
26 changes: 26 additions & 0 deletions pkg/shim/v1/runsccmd/runsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,32 @@ func (r *Runsc) Restore(context context.Context, id string, cio runc.IO, opts *R
return r.start(context, cio, r.command(context, append(args, id)...))
}

// CheckpointOpts is a set of options to runsc.Checkpoint().
type CheckpointOpts struct {
ImagePath string
LeaveRunning bool
}

func (o *CheckpointOpts) args() []string {
var out []string
if o.ImagePath != "" {
out = append(out, fmt.Sprintf("--image-path=%s", o.ImagePath))
}
if o.LeaveRunning {
out = append(out, "--leave-running")
}
return out
}

// Checkpoint checkpoints the container.
func (r *Runsc) Checkpoint(context context.Context, id string, opts *CheckpointOpts) error {
args := []string{"checkpoint"}
if opts != nil {
args = append(args, opts.args()...)
}
return r.runOrError(r.command(context, append(args, id)...))
}

type waitResult struct {
ID string `json:"id"`
ExitStatus int `json:"exitStatus"`
Expand Down