Update checkpoint opts with runtime handling
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
160737d2c8
commit
aaae81189a
@ -461,7 +461,7 @@ func TestCRWithImagePath(t *testing.T) {
|
|||||||
defer os.RemoveAll(crDir)
|
defer os.RemoveAll(crDir)
|
||||||
imagePath := filepath.Join(crDir, "cr")
|
imagePath := filepath.Join(crDir, "cr")
|
||||||
// checkpoint task
|
// 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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
task.go
19
task.go
@ -117,6 +117,13 @@ type CheckpointTaskInfo struct {
|
|||||||
ParentCheckpoint digest.Digest
|
ParentCheckpoint digest.Digest
|
||||||
// Options hold runtime specific settings for checkpointing a task
|
// Options hold runtime specific settings for checkpointing a task
|
||||||
Options interface{}
|
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
|
// 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
|
return nil, err
|
||||||
}
|
}
|
||||||
defer done(ctx)
|
defer done(ctx)
|
||||||
|
cr, err := t.client.ContainerService().Get(ctx, t.id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
request := &tasks.CheckpointTaskRequest{
|
request := &tasks.CheckpointTaskRequest{
|
||||||
ContainerID: t.id,
|
ContainerID: t.id,
|
||||||
}
|
}
|
||||||
var i CheckpointTaskInfo
|
i := CheckpointTaskInfo{
|
||||||
|
runtime: cr.Runtime.Name,
|
||||||
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(&i); err != nil {
|
if err := o(&i); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -434,10 +447,6 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer t.Resume(ctx)
|
defer t.Resume(ctx)
|
||||||
cr, err := t.client.ContainerService().Get(ctx, t.id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
index := v1.Index{
|
index := v1.Index{
|
||||||
Versioned: is.Versioned{
|
Versioned: is.Versioned{
|
||||||
SchemaVersion: 2,
|
SchemaVersion: 2,
|
||||||
|
@ -92,9 +92,9 @@ func WithCheckpointName(name string) CheckpointTaskOpts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithCheckpointImagePath sets image path for checkpoint option
|
// WithCheckpointImagePath sets image path for checkpoint option
|
||||||
func WithCheckpointImagePath(rt, path string) CheckpointTaskOpts {
|
func WithCheckpointImagePath(path string) CheckpointTaskOpts {
|
||||||
return func(r *CheckpointTaskInfo) error {
|
return func(r *CheckpointTaskInfo) error {
|
||||||
if CheckRuntime(rt, "io.containerd.runc") {
|
if CheckRuntime(r.Runtime(), "io.containerd.runc") {
|
||||||
if r.Options == nil {
|
if r.Options == nil {
|
||||||
r.Options = &options.CheckpointOptions{}
|
r.Options = &options.CheckpointOptions{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user