cr: support checkpoint/restore without image
support checkpoint without committing a checkpoint dir into a checkpoint image and restore without untar image into checkpoint directory. support for both v1 and v2 runtime Signed-off-by: Ace-Tang <aceapril@126.com>
This commit is contained in:
29
task.go
29
task.go
@@ -37,6 +37,8 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/rootfs"
|
||||
"github.com/containerd/containerd/runtime/linux/runctypes"
|
||||
"github.com/containerd/containerd/runtime/v2/runc/options"
|
||||
"github.com/containerd/typeurl"
|
||||
google_protobuf "github.com/gogo/protobuf/types"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
@@ -433,6 +435,11 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
|
||||
if err := t.checkpointTask(ctx, &index, request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// if checkpoint image path passed, jump checkpoint image
|
||||
if isCheckpointPathExist(cr.Runtime.Name, i.Options) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if cr.Image != "" {
|
||||
if err := t.checkpointImage(ctx, &index, cr.Image); err != nil {
|
||||
return nil, err
|
||||
@@ -542,6 +549,7 @@ func (t *task) checkpointTask(ctx context.Context, index *v1.Index, request *tas
|
||||
if err != nil {
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
// NOTE: response.Descriptors can be an empty slice if checkpoint image is jumped
|
||||
// add the checkpoint descriptors to the index
|
||||
for _, d := range response.Descriptors {
|
||||
index.Manifests = append(index.Manifests, v1.Descriptor{
|
||||
@@ -619,3 +627,24 @@ func writeContent(ctx context.Context, store content.Ingester, mediaType, ref st
|
||||
Size: size,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// isCheckpointPathExist only suitable for runc runtime now
|
||||
func isCheckpointPathExist(runtime string, v interface{}) bool {
|
||||
if v == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
switch runtime {
|
||||
case "io.containerd.runc.v1":
|
||||
if opts, ok := v.(*options.CheckpointOptions); ok && opts.ImagePath != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
case "io.containerd.runtime.v1.linux":
|
||||
if opts, ok := v.(*runctypes.CheckpointOptions); ok && opts.ImagePath != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user