ctr: allow run to override mounts
If a mount destination is specified both in the default spec and in a --mount option, remove the default mount before adding new mounts. This allows overriding the default sysfs mount, for example. Signed-off-by: Samuel Karp <samuelkarp@google.com>
This commit is contained in:
parent
5997a65896
commit
3d7522b7f2
@ -24,6 +24,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
|
gocni "github.com/containerd/go-cni"
|
||||||
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
"github.com/containerd/containerd/cio"
|
"github.com/containerd/containerd/cio"
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
@ -32,22 +36,21 @@ import (
|
|||||||
clabels "github.com/containerd/containerd/labels"
|
clabels "github.com/containerd/containerd/labels"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
gocni "github.com/containerd/go-cni"
|
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
"github.com/urfave/cli"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func withMounts(context *cli.Context) oci.SpecOpts {
|
func withMounts(context *cli.Context) oci.SpecOpts {
|
||||||
return func(ctx gocontext.Context, client oci.Client, container *containers.Container, s *specs.Spec) error {
|
return func(ctx gocontext.Context, client oci.Client, container *containers.Container, s *specs.Spec) error {
|
||||||
mounts := make([]specs.Mount, 0)
|
mounts := make([]specs.Mount, 0)
|
||||||
|
dests := make([]string, 0)
|
||||||
for _, mount := range context.StringSlice("mount") {
|
for _, mount := range context.StringSlice("mount") {
|
||||||
m, err := parseMountFlag(mount)
|
m, err := parseMountFlag(mount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
mounts = append(mounts, m)
|
mounts = append(mounts, m)
|
||||||
|
dests = append(dests, m.Destination)
|
||||||
}
|
}
|
||||||
return oci.WithMounts(mounts)(ctx, client, container, s)
|
return oci.Compose(oci.WithoutMounts(dests...), oci.WithMounts(mounts))(ctx, client, container, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user