Merge pull request #5660 from BigVan/main

Add ctr command label in NewContainerOpts
This commit is contained in:
Phil Estes 2021-06-29 15:03:43 -04:00 committed by GitHub
commit 25d7f907c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 3 deletions

View File

@ -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 is a cli flag specifying labels
LabelFlag = cli.StringSliceFlag{ LabelFlag = cli.StringSliceFlag{
Name: "label", Name: "label",

View File

@ -55,7 +55,7 @@ var createCommand = cli.Command{
Name: "create", Name: "create",
Usage: "create container", Usage: "create container",
ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]", 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 { Action: func(context *cli.Context) error {
var ( var (
id string id string

View File

@ -122,7 +122,9 @@ var Command = cli.Command{
Name: "platform", Name: "platform",
Usage: "run image for specific 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 { Action: func(context *cli.Context) error {
var ( var (
err error err error

View File

@ -35,6 +35,7 @@ import (
runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1" runtimeoptions "github.com/containerd/containerd/pkg/runtimeoptions/v1"
"github.com/containerd/containerd/platforms" "github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/runtime/v2/runc/options" "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/containerd/snapshots"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "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) // 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, // We pass writable snapshot to the OCI runtime, and the runtime remounts it as read-only,
// after creating some mount points on demand. // 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")) cOpts = append(cOpts, containerd.WithImageStopSignal(image, "SIGTERM"))
} }