feat: Add snapshotter label to the new snapshot for container.
add '--snapshotter-labels' in ctr run and ctr c create which can pass labels to snappshotter on preparing new snapshot. Pass command label to snapshotter can help it determine which kind of writable snapshots should be provide. For some snapshotter, such as overlaybd: ( https://github.com/alibaba/accelerated-container-image ), it can provide 2 kind of writable snapshot (overlayfs dir or blockdevice) by command label values. Signed-off-by: Yifan Yuan <tuji.yyf@alibaba-inc.com>
This commit is contained in:
parent
e1f28659bc
commit
bda7b58666
@ -37,6 +37,12 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
// SnapshotterLabels are cli flags specifying labels which will be add to the new snapshot for container.
|
||||
SnapshotterLabels = cli.StringSliceFlag{
|
||||
Name: "snapshotter-label",
|
||||
Usage: "labels added to the new snapshot for this container.",
|
||||
}
|
||||
|
||||
// LabelFlag is a cli flag specifying labels
|
||||
LabelFlag = cli.StringSliceFlag{
|
||||
Name: "label",
|
||||
|
@ -55,7 +55,7 @@ var createCommand = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "create container",
|
||||
ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]",
|
||||
Flags: append(commands.SnapshotterFlags, commands.ContainerFlags...),
|
||||
Flags: append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...),
|
||||
Action: func(context *cli.Context) error {
|
||||
var (
|
||||
id string
|
||||
|
@ -122,7 +122,9 @@ var Command = cli.Command{
|
||||
Name: "platform",
|
||||
Usage: "run image for specific platform",
|
||||
},
|
||||
}, append(platformRunFlags, append(commands.SnapshotterFlags, commands.ContainerFlags...)...)...),
|
||||
}, append(platformRunFlags,
|
||||
append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...),
|
||||
commands.ContainerFlags...)...)...),
|
||||
Action: func(context *cli.Context) error {
|
||||
var (
|
||||
err error
|
||||
|
@ -35,6 +35,7 @@ import (
|
||||
runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/runtime/v2/runc/options"
|
||||
"github.com/containerd/containerd/snapshots"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -171,7 +172,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
|
||||
// Even when "read-only" is set, we don't use KindView snapshot here. (#1495)
|
||||
// We pass writable snapshot to the OCI runtime, and the runtime remounts it as read-only,
|
||||
// after creating some mount points on demand.
|
||||
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image))
|
||||
// For some snapshotter, such as overlaybd, it can provide 2 kind of writable snapshot(overlayfs dir or block-device)
|
||||
// by command label values.
|
||||
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
|
||||
snapshots.WithLabels(commands.LabelArgs(context.StringSlice("snapshotter-label")))))
|
||||
}
|
||||
cOpts = append(cOpts, containerd.WithImageStopSignal(image, "SIGTERM"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user