cmd/ctr: create an image for checkpoint
This allows one to manage the checkpoints by using the `ctr image` command. The image is created with label "containerd.io/checkpoint". By default, it is not included in the output of `ctr images ls`. We can list the images by using the following command: $ ctr images ls labels.containerd.\"io/checkpoint\"==true Fixes #1026 Signed-off-by: Jacob Wen <jian.w.wen@oracle.com>
This commit is contained in:
parent
70b5668351
commit
abbec62620
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -48,6 +49,19 @@ var taskCheckpointCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
labels := map[string]string{
|
||||
"containerd.io/checkpoint": "true",
|
||||
}
|
||||
img := images.Image{
|
||||
Name: checkpoint.Digest.String(),
|
||||
Target: checkpoint,
|
||||
Labels: labels,
|
||||
}
|
||||
_, err = client.ImageService().Create(ctx, img)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(checkpoint.Digest.String())
|
||||
return nil
|
||||
},
|
||||
|
@ -57,6 +57,16 @@ var imagesListCommand = cli.Command{
|
||||
imageStore := client.ImageService()
|
||||
cs := client.ContentStore()
|
||||
|
||||
if len(filters) == 0 {
|
||||
filters = append(filters, `labels.containerd."io/checkpoint"!=true`)
|
||||
} else {
|
||||
for _, f := range filters {
|
||||
if !strings.Contains(f, `labels.containerd."io/checkpoint"`) {
|
||||
f += `,labels.containerd."io/checkpoint"!=true`
|
||||
_ = f // ignore error: ineffectual assignment to f
|
||||
}
|
||||
}
|
||||
}
|
||||
imageList, err := imageStore.List(ctx, filters...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list images")
|
||||
|
Loading…
Reference in New Issue
Block a user