Skip to content

Commit bda7b58

Browse files
committed
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 <[email protected]>
1 parent e1f2865 commit bda7b58

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

cmd/ctr/commands/commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ var (
3737
},
3838
}
3939

40+
// SnapshotterLabels are cli flags specifying labels which will be add to the new snapshot for container.
41+
SnapshotterLabels = cli.StringSliceFlag{
42+
Name: "snapshotter-label",
43+
Usage: "labels added to the new snapshot for this container.",
44+
}
45+
4046
// LabelFlag is a cli flag specifying labels
4147
LabelFlag = cli.StringSliceFlag{
4248
Name: "label",

cmd/ctr/commands/containers/containers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var createCommand = cli.Command{
5555
Name: "create",
5656
Usage: "create container",
5757
ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]",
58-
Flags: append(commands.SnapshotterFlags, commands.ContainerFlags...),
58+
Flags: append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...),
5959
Action: func(context *cli.Context) error {
6060
var (
6161
id string

cmd/ctr/commands/run/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ var Command = cli.Command{
122122
Name: "platform",
123123
Usage: "run image for specific platform",
124124
},
125-
}, append(platformRunFlags, append(commands.SnapshotterFlags, commands.ContainerFlags...)...)...),
125+
}, append(platformRunFlags,
126+
append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...),
127+
commands.ContainerFlags...)...)...),
126128
Action: func(context *cli.Context) error {
127129
var (
128130
err error

cmd/ctr/commands/run/run_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1"
3636
"github.com/containerd/containerd/platforms"
3737
"github.com/containerd/containerd/runtime/v2/runc/options"
38+
"github.com/containerd/containerd/snapshots"
3839
"github.com/opencontainers/runtime-spec/specs-go"
3940
"github.com/pkg/errors"
4041
"github.com/sirupsen/logrus"
@@ -171,7 +172,10 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
171172
// Even when "read-only" is set, we don't use KindView snapshot here. (#1495)
172173
// We pass writable snapshot to the OCI runtime, and the runtime remounts it as read-only,
173174
// after creating some mount points on demand.
174-
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image))
175+
// For some snapshotter, such as overlaybd, it can provide 2 kind of writable snapshot(overlayfs dir or block-device)
176+
// by command label values.
177+
cOpts = append(cOpts, containerd.WithNewSnapshot(id, image,
178+
snapshots.WithLabels(commands.LabelArgs(context.StringSlice("snapshotter-label")))))
175179
}
176180
cOpts = append(cOpts, containerd.WithImageStopSignal(image, "SIGTERM"))
177181
}

0 commit comments

Comments
 (0)