Skip to content

Commit aaae811

Browse files
committed
Update checkpoint opts with runtime handling
Signed-off-by: Michael Crosby <[email protected]>
1 parent 160737d commit aaae811

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

container_checkpoint_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func TestCRWithImagePath(t *testing.T) {
461461
defer os.RemoveAll(crDir)
462462
imagePath := filepath.Join(crDir, "cr")
463463
// checkpoint task
464-
if _, err := task.Checkpoint(ctx, WithCheckpointImagePath(client.runtime, imagePath)); err != nil {
464+
if _, err := task.Checkpoint(ctx, WithCheckpointImagePath(imagePath)); err != nil {
465465
t.Fatal(err)
466466
}
467467

task.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ type CheckpointTaskInfo struct {
117117
ParentCheckpoint digest.Digest
118118
// Options hold runtime specific settings for checkpointing a task
119119
Options interface{}
120+
121+
runtime string
122+
}
123+
124+
// Runtime name for the container
125+
func (i *CheckpointTaskInfo) Runtime() string {
126+
return i.runtime
120127
}
121128

122129
// CheckpointTaskOpts allows the caller to set checkpoint options
@@ -407,11 +414,17 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
407414
return nil, err
408415
}
409416
defer done(ctx)
417+
cr, err := t.client.ContainerService().Get(ctx, t.id)
418+
if err != nil {
419+
return nil, err
420+
}
410421

411422
request := &tasks.CheckpointTaskRequest{
412423
ContainerID: t.id,
413424
}
414-
var i CheckpointTaskInfo
425+
i := CheckpointTaskInfo{
426+
runtime: cr.Runtime.Name,
427+
}
415428
for _, o := range opts {
416429
if err := o(&i); err != nil {
417430
return nil, err
@@ -434,10 +447,6 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
434447
return nil, err
435448
}
436449
defer t.Resume(ctx)
437-
cr, err := t.client.ContainerService().Get(ctx, t.id)
438-
if err != nil {
439-
return nil, err
440-
}
441450
index := v1.Index{
442451
Versioned: is.Versioned{
443452
SchemaVersion: 2,

task_opts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ func WithCheckpointName(name string) CheckpointTaskOpts {
9292
}
9393

9494
// WithCheckpointImagePath sets image path for checkpoint option
95-
func WithCheckpointImagePath(rt, path string) CheckpointTaskOpts {
95+
func WithCheckpointImagePath(path string) CheckpointTaskOpts {
9696
return func(r *CheckpointTaskInfo) error {
97-
if CheckRuntime(rt, "io.containerd.runc") {
97+
if CheckRuntime(r.Runtime(), "io.containerd.runc") {
9898
if r.Options == nil {
9999
r.Options = &options.CheckpointOptions{}
100100
}

0 commit comments

Comments
 (0)