From aaae81189a40f63ff8b03a786adcbed5d0651c8a Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 6 Mar 2019 12:42:45 -0500 Subject: [PATCH] Update checkpoint opts with runtime handling Signed-off-by: Michael Crosby --- container_checkpoint_test.go | 2 +- task.go | 19 ++++++++++++++----- task_opts.go | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/container_checkpoint_test.go b/container_checkpoint_test.go index 0ed97dee9..68d3493f3 100644 --- a/container_checkpoint_test.go +++ b/container_checkpoint_test.go @@ -461,7 +461,7 @@ func TestCRWithImagePath(t *testing.T) { defer os.RemoveAll(crDir) imagePath := filepath.Join(crDir, "cr") // checkpoint task - if _, err := task.Checkpoint(ctx, WithCheckpointImagePath(client.runtime, imagePath)); err != nil { + if _, err := task.Checkpoint(ctx, WithCheckpointImagePath(imagePath)); err != nil { t.Fatal(err) } diff --git a/task.go b/task.go index 14a81e12a..c81aa37f7 100644 --- a/task.go +++ b/task.go @@ -117,6 +117,13 @@ type CheckpointTaskInfo struct { ParentCheckpoint digest.Digest // Options hold runtime specific settings for checkpointing a task Options interface{} + + runtime string +} + +// Runtime name for the container +func (i *CheckpointTaskInfo) Runtime() string { + return i.runtime } // CheckpointTaskOpts allows the caller to set checkpoint options @@ -407,11 +414,17 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag return nil, err } defer done(ctx) + cr, err := t.client.ContainerService().Get(ctx, t.id) + if err != nil { + return nil, err + } request := &tasks.CheckpointTaskRequest{ ContainerID: t.id, } - var i CheckpointTaskInfo + i := CheckpointTaskInfo{ + runtime: cr.Runtime.Name, + } for _, o := range opts { if err := o(&i); err != nil { return nil, err @@ -434,10 +447,6 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag return nil, err } defer t.Resume(ctx) - cr, err := t.client.ContainerService().Get(ctx, t.id) - if err != nil { - return nil, err - } index := v1.Index{ Versioned: is.Versioned{ SchemaVersion: 2, diff --git a/task_opts.go b/task_opts.go index 0b3054981..c0e98b30b 100644 --- a/task_opts.go +++ b/task_opts.go @@ -92,9 +92,9 @@ func WithCheckpointName(name string) CheckpointTaskOpts { } // WithCheckpointImagePath sets image path for checkpoint option -func WithCheckpointImagePath(rt, path string) CheckpointTaskOpts { +func WithCheckpointImagePath(path string) CheckpointTaskOpts { return func(r *CheckpointTaskInfo) error { - if CheckRuntime(rt, "io.containerd.runc") { + if CheckRuntime(r.Runtime(), "io.containerd.runc") { if r.Options == nil { r.Options = &options.CheckpointOptions{} }