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>
| ... | ... |
@@ -511,26 +511,39 @@ func (c *client) Status(ctx context.Context, containerID string) (containerd.Pro |
| 511 | 511 |
return s.Status, nil |
| 512 | 512 |
} |
| 513 | 513 |
|
| 514 |
+func (c *client) getCheckpointOptions(id string, exit bool) containerd.CheckpointTaskOpts {
|
|
| 515 |
+ return func(r *containerd.CheckpointTaskInfo) error {
|
|
| 516 |
+ if r.Options == nil {
|
|
| 517 |
+ c.v2runcoptionsMu.Lock() |
|
| 518 |
+ _, isV2 := c.v2runcoptions[id] |
|
| 519 |
+ c.v2runcoptionsMu.Unlock() |
|
| 520 |
+ |
|
| 521 |
+ if isV2 {
|
|
| 522 |
+ r.Options = &v2runcoptions.CheckpointOptions{Exit: exit}
|
|
| 523 |
+ } else {
|
|
| 524 |
+ r.Options = &runctypes.CheckpointOptions{Exit: exit}
|
|
| 525 |
+ } |
|
| 526 |
+ return nil |
|
| 527 |
+ } |
|
| 528 |
+ |
|
| 529 |
+ switch opts := r.Options.(type) {
|
|
| 530 |
+ case *v2runcoptions.CheckpointOptions: |
|
| 531 |
+ opts.Exit = exit |
|
| 532 |
+ case *runctypes.CheckpointOptions: |
|
| 533 |
+ opts.Exit = exit |
|
| 534 |
+ } |
|
| 535 |
+ |
|
| 536 |
+ return nil |
|
| 537 |
+ } |
|
| 538 |
+} |
|
| 539 |
+ |
|
| 514 | 540 |
func (c *client) CreateCheckpoint(ctx context.Context, containerID, checkpointDir string, exit bool) error {
|
| 515 | 541 |
p, err := c.getProcess(ctx, containerID, libcontainerdtypes.InitProcessName) |
| 516 | 542 |
if err != nil {
|
| 517 | 543 |
return err |
| 518 | 544 |
} |
| 519 | 545 |
|
| 520 |
- opts := []containerd.CheckpointTaskOpts{}
|
|
| 521 |
- if exit {
|
|
| 522 |
- opts = append(opts, func(r *containerd.CheckpointTaskInfo) error {
|
|
| 523 |
- if r.Options == nil {
|
|
| 524 |
- r.Options = &runctypes.CheckpointOptions{
|
|
| 525 |
- Exit: true, |
|
| 526 |
- } |
|
| 527 |
- } else {
|
|
| 528 |
- opts, _ := r.Options.(*runctypes.CheckpointOptions) |
|
| 529 |
- opts.Exit = true |
|
| 530 |
- } |
|
| 531 |
- return nil |
|
| 532 |
- }) |
|
| 533 |
- } |
|
| 546 |
+ opts := []containerd.CheckpointTaskOpts{c.getCheckpointOptions(containerID, exit)}
|
|
| 534 | 547 |
img, err := p.(containerd.Task).Checkpoint(ctx, opts...) |
| 535 | 548 |
if err != nil {
|
| 536 | 549 |
return wrapError(err) |