From abbec626202c7cafa81daa2d44ae1f0aed7e97f4 Mon Sep 17 00:00:00 2001 From: Jacob Wen Date: Thu, 14 Sep 2017 15:38:48 +0800 Subject: [PATCH] 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 --- cmd/ctr/checkpoint.go | 14 ++++++++++++++ cmd/ctr/images.go | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/ctr/checkpoint.go b/cmd/ctr/checkpoint.go index f34fc83ab..9841a92aa 100644 --- a/cmd/ctr/checkpoint.go +++ b/cmd/ctr/checkpoint.go @@ -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 }, diff --git a/cmd/ctr/images.go b/cmd/ctr/images.go index 6be8b9ccb..c355f0c7e 100644 --- a/cmd/ctr/images.go +++ b/cmd/ctr/images.go @@ -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")