Create checkpointed image in client
Allow a user provided name for the checkpoint as well as a default generated name for the checkpoint image. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
59
task.go
59
task.go
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/diff"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
@@ -88,6 +89,7 @@ func WithStdinCloser(r *IOCloseInfo) {
|
||||
|
||||
// CheckpointTaskInfo allows specific checkpoint information to be set for the task
|
||||
type CheckpointTaskInfo struct {
|
||||
Name string
|
||||
// ParentCheckpoint is the digest of a parent checkpoint
|
||||
ParentCheckpoint digest.Digest
|
||||
// Options hold runtime specific settings for checkpointing a task
|
||||
@@ -124,7 +126,7 @@ type Task interface {
|
||||
// OCI Index that can be push and pulled from a remote resource.
|
||||
//
|
||||
// Additional software like CRIU maybe required to checkpoint and restore tasks
|
||||
Checkpoint(context.Context, ...CheckpointTaskOpts) (v1.Descriptor, error)
|
||||
Checkpoint(context.Context, ...CheckpointTaskOpts) (Image, error)
|
||||
// Update modifies executing tasks with updated settings
|
||||
Update(context.Context, ...UpdateTaskOpts) error
|
||||
// LoadProcess loads a previously created exec'd process
|
||||
@@ -350,46 +352,73 @@ func (t *task) Resize(ctx context.Context, w, h uint32) error {
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
|
||||
func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (d v1.Descriptor, err error) {
|
||||
func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Image, error) {
|
||||
request := &tasks.CheckpointTaskRequest{
|
||||
ContainerID: t.id,
|
||||
}
|
||||
var i CheckpointTaskInfo
|
||||
for _, o := range opts {
|
||||
if err := o(&i); err != nil {
|
||||
return d, err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
const checkpointDateFormat = "01-02-2006-15:04:05"
|
||||
// set a default name
|
||||
if i.Name == "" {
|
||||
i.Name = fmt.Sprintf("io.containerd/checkpoint/%s:%s", t.id, time.Now().Format(checkpointDateFormat))
|
||||
}
|
||||
request.ParentCheckpoint = i.ParentCheckpoint
|
||||
if i.Options != nil {
|
||||
any, err := typeurl.MarshalAny(i.Options)
|
||||
if err != nil {
|
||||
return d, err
|
||||
return nil, err
|
||||
}
|
||||
request.Options = any
|
||||
}
|
||||
// make sure we pause it and resume after all other filesystem operations are completed
|
||||
if err := t.Pause(ctx); err != nil {
|
||||
return d, err
|
||||
return nil, err
|
||||
}
|
||||
defer t.Resume(ctx)
|
||||
cr, err := t.client.ContainerService().Get(ctx, t.id)
|
||||
if err != nil {
|
||||
return d, err
|
||||
return nil, err
|
||||
}
|
||||
index := v1.Index{
|
||||
Annotations: make(map[string]string),
|
||||
}
|
||||
var index v1.Index
|
||||
if err := t.checkpointTask(ctx, &index, request); err != nil {
|
||||
return d, err
|
||||
return nil, err
|
||||
}
|
||||
if err := t.checkpointImage(ctx, &index, cr.Image); err != nil {
|
||||
return d, err
|
||||
if cr.Image != "" {
|
||||
if err := t.checkpointImage(ctx, &index, cr.Image); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
index.Annotations["image.name"] = cr.Image
|
||||
}
|
||||
if err := t.checkpointRWSnapshot(ctx, &index, cr.Snapshotter, cr.SnapshotKey); err != nil {
|
||||
return d, err
|
||||
if cr.SnapshotKey != "" {
|
||||
if err := t.checkpointRWSnapshot(ctx, &index, cr.Snapshotter, cr.SnapshotKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
index.Annotations = make(map[string]string)
|
||||
index.Annotations["image.name"] = cr.Image
|
||||
return t.writeIndex(ctx, &index)
|
||||
desc, err := t.writeIndex(ctx, &index)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
im := images.Image{
|
||||
Name: i.Name,
|
||||
Target: desc,
|
||||
Labels: map[string]string{
|
||||
"containerd.io/checkpoint": "true",
|
||||
},
|
||||
}
|
||||
if im, err = t.client.ImageService().Create(ctx, im); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &image{
|
||||
client: t.client,
|
||||
i: im,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UpdateTaskInfo allows updated specific settings to be changed on a task
|
||||
|
Reference in New Issue
Block a user