support using multiple snapshotters simultaneously

e.g. dist pull --snapshotter btrfs ...; ctr run --snapshotter btrfs ...
(empty string defaults for overlayfs)

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Akihiro Suda
2017-07-11 09:10:57 +00:00
committed by Michael Crosby
parent 8f1c11d862
commit b06aab713a
22 changed files with 743 additions and 255 deletions

View File

@@ -48,7 +48,7 @@ var runCommand = cli.Command{
Name: "run",
Usage: "run a container",
ArgsUsage: "IMAGE ID [COMMAND] [ARG...]",
Flags: []cli.Flag{
Flags: append([]cli.Flag{
cli.BoolFlag{
Name: "tty,t",
Usage: "allocate a TTY for the container",
@@ -86,7 +86,7 @@ var runCommand = cli.Command{
Name: "checkpoint",
Usage: "provide the checkpoint digest to restore the container",
},
},
}, snapshotterFlags...),
Action: func(context *cli.Context) error {
var (
err error

View File

@@ -106,6 +106,7 @@ func newContainer(ctx gocontext.Context, client *containerd.Client, context *cli
containerd.WithSpec(spec),
containerd.WithImage(image),
containerd.WithContainerLabels(labels),
containerd.WithSnapshotter(context.String("snapshotter")),
rootfs,
)
}

View File

@@ -19,6 +19,7 @@ import (
var snapshotCommand = cli.Command{
Name: "snapshot",
Usage: "snapshot management",
Flags: snapshotterFlags,
Subcommands: cli.Commands{
archiveSnapshotCommand,
listSnapshotCommand,
@@ -79,13 +80,11 @@ var listSnapshotCommand = cli.Command{
ctx, cancel := appContext(clicontext)
defer cancel()
client, err := newClient(clicontext)
snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}
snapshotter := client.SnapshotService()
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
fmt.Fprintln(tw, "ID\tParent\tState\tReadonly\t")
@@ -125,11 +124,6 @@ var usageSnapshotCommand = cli.Command{
ctx, cancel := appContext(clicontext)
defer cancel()
client, err := newClient(clicontext)
if err != nil {
return err
}
var displaySize func(int64) string
if clicontext.Bool("b") {
displaySize = func(s int64) string {
@@ -141,7 +135,10 @@ var usageSnapshotCommand = cli.Command{
}
}
snapshotter := client.SnapshotService()
snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0)
fmt.Fprintln(tw, "ID\tSize\tInodes\t")
@@ -180,13 +177,11 @@ var removeSnapshotCommand = cli.Command{
ctx, cancel := appContext(clicontext)
defer cancel()
client, err := newClient(clicontext)
snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}
snapshotter := client.SnapshotService()
for _, id := range clicontext.Args() {
err = snapshotter.Remove(ctx, id)
if err != nil {
@@ -219,12 +214,11 @@ var prepareSnapshotCommand = cli.Command{
logrus.Infof("preparing mounts %s", dgst.String())
client, err := newClient(clicontext)
snapshotter, err := getSnapshotter(clicontext)
if err != nil {
return err
}
snapshotter := client.SnapshotService()
mounts, err := snapshotter.Prepare(ctx, target, dgst.String())
if err != nil {
return err

View File

@@ -35,6 +35,13 @@ import (
"google.golang.org/grpc"
)
var snapshotterFlags = []cli.Flag{
cli.StringFlag{
Name: "snapshotter",
Usage: "Snapshotter name. Empty value stands for the daemon default value.",
},
}
var grpcConn *grpc.ClientConn
// appContext returns the context for a command. Should only be called once per
@@ -111,7 +118,7 @@ func getSnapshotter(context *cli.Context) (snapshot.Snapshotter, error) {
if err != nil {
return nil, err
}
return snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotsClient(conn)), nil
return snapshotservice.NewSnapshotterFromClient(snapshotapi.NewSnapshotsClient(conn), context.GlobalString("snapshotter")), nil
}
func getImageStore(clicontext *cli.Context) (images.Store, error) {

7
cmd/dist/common.go vendored
View File

@@ -44,6 +44,13 @@ var registryFlags = []cli.Flag{
},
}
var snapshotterFlags = []cli.Flag{
cli.StringFlag{
Name: "snapshotter",
Usage: "Snapshotter name. Empty value stands for the daemon default value.",
},
}
func getClient(context *cli.Context) (*containerd.Client, error) {
address := context.GlobalString("address")
//timeout := context.GlobalDuration("connect-timeout")

4
cmd/dist/pull.go vendored
View File

@@ -20,7 +20,7 @@ command. As part of this process, we do the following:
2. Prepare the snapshot filesystem with the pulled resources.
3. Register metadata for the image.
`,
Flags: registryFlags,
Flags: append(registryFlags, snapshotterFlags...),
Action: func(clicontext *cli.Context) error {
var (
ref = clicontext.Args().First()
@@ -38,7 +38,7 @@ command. As part of this process, we do the following:
// TODO: Show unpack status
fmt.Printf("unpacking %s...", img.Target().Digest)
err = img.Unpack(ctx)
err = img.Unpack(ctx, clicontext.String("snapshotter"))
fmt.Println("done")
return err
},

4
cmd/dist/rootfs.go vendored
View File

@@ -21,7 +21,7 @@ var rootfsUnpackCommand = cli.Command{
Name: "unpack",
Usage: "unpack applies layers from a manifest to a snapshot",
ArgsUsage: "[flags] <digest>",
Flags: []cli.Flag{},
Flags: snapshotterFlags,
Action: func(clicontext *cli.Context) error {
ctx, cancel := appContext(clicontext)
defer cancel()
@@ -49,7 +49,7 @@ var rootfsUnpackCommand = cli.Command{
for _, image := range images {
if image.Target().Digest == dgst {
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
if err := image.Unpack(ctx); err != nil {
if err := image.Unpack(ctx, clicontext.String("snapshotter")); err != nil {
fmt.Println()
return err
}