Skip to content

Commit

Permalink
"Fix" checkpoint on v2 runtime
Browse files Browse the repository at this point in the history
Checkpoint/Restore is horribly broken all around.
But on the, now default, v2 runtime it's even more broken.

This at least makes checkpoint equally broken on both runtimes.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Oct 12, 2020
1 parent 9c15e82 commit f14aea6
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions libcontainerd/remote/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,26 +511,39 @@ func (c *client) Status(ctx context.Context, containerID string) (containerd.Pro
return s.Status, nil
}

func (c *client) getCheckpointOptions(id string, exit bool) containerd.CheckpointTaskOpts {
return func(r *containerd.CheckpointTaskInfo) error {
if r.Options == nil {
c.v2runcoptionsMu.Lock()
_, isV2 := c.v2runcoptions[id]
c.v2runcoptionsMu.Unlock()

if isV2 {
r.Options = &v2runcoptions.CheckpointOptions{Exit: exit}
} else {
r.Options = &runctypes.CheckpointOptions{Exit: exit}
}
return nil
}

switch opts := r.Options.(type) {
case *v2runcoptions.CheckpointOptions:
opts.Exit = exit
case *runctypes.CheckpointOptions:
opts.Exit = exit
}

return nil
}
}

func (c *client) CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error {
p, err := c.getProcess(ctx, containerID, libcontainerdtypes.InitProcessName)
if err != nil {
return err
}

opts := []containerd.CheckpointTaskOpts{}
if exit {
opts = append(opts, func(r *containerd.CheckpointTaskInfo) error {
if r.Options == nil {
r.Options = &runctypes.CheckpointOptions{
Exit: true,
}
} else {
opts, _ := r.Options.(*runctypes.CheckpointOptions)
opts.Exit = true
}
return nil
})
}
opts := []containerd.CheckpointTaskOpts{c.getCheckpointOptions(containerID, exit)}
img, err := p.(containerd.Task).Checkpoint(ctx, opts...)
if err != nil {
return wrapError(err)
Expand Down

0 comments on commit f14aea6

Please sign in to comment.