diff --git a/cmd/ctr/commands/commands.go b/cmd/ctr/commands/commands.go index d0e52a652..b1ca29d3a 100644 --- a/cmd/ctr/commands/commands.go +++ b/cmd/ctr/commands/commands.go @@ -165,10 +165,6 @@ var ( Name: "memory-limit", Usage: "memory limit (in bytes) for the container", }, - cli.StringSliceFlag{ - Name: "device", - Usage: "file path to a device to add to the container; or a path to a directory tree of devices to add to the container", - }, cli.StringSliceFlag{ Name: "cap-add", Usage: "add Linux capabilities (Set capabilities with 'CAP_' prefix)", diff --git a/cmd/ctr/commands/commands_unix.go b/cmd/ctr/commands/commands_unix.go index 44b81e183..6ba5332a8 100644 --- a/cmd/ctr/commands/commands_unix.go +++ b/cmd/ctr/commands/commands_unix.go @@ -40,5 +40,8 @@ func init() { }, cli.StringFlag{ Name: "rootfs-propagation", Usage: "set the propagation of the container rootfs", + }, cli.StringSliceFlag{ + Name: "device", + Usage: "file path to a device to add to the container; or a path to a directory tree of devices to add to the container", }) } diff --git a/cmd/ctr/commands/commands_windows.go b/cmd/ctr/commands/commands_windows.go index 5c1d98e3d..10a5d6a5d 100644 --- a/cmd/ctr/commands/commands_windows.go +++ b/cmd/ctr/commands/commands_windows.go @@ -24,5 +24,8 @@ func init() { ContainerFlags = append(ContainerFlags, cli.Uint64Flag{ Name: "cpu-count", Usage: "number of CPUs available to the container", + }, cli.StringSliceFlag{ + Name: "device", + Usage: "identifier of a device to add to the container (e.g. class://5B45201D-F2F2-4F3B-85BB-30FF1F953599)", }) } diff --git a/cmd/ctr/commands/run/run_windows.go b/cmd/ctr/commands/run/run_windows.go index 5e5006430..60efca42f 100644 --- a/cmd/ctr/commands/run/run_windows.go +++ b/cmd/ctr/commands/run/run_windows.go @@ -19,6 +19,7 @@ package run import ( gocontext "context" "errors" + "strings" "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options" "github.com/containerd/console" @@ -142,6 +143,16 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli if ccount != 0 { opts = append(opts, oci.WithWindowsCPUCount(ccount)) } + for _, dev := range context.StringSlice("device") { + parts := strings.Split(dev, "://") + if len(parts) != 2 { + return nil, errors.New("devices must be in the format IDType://ID") + } + if parts[0] == "" { + return nil, errors.New("devices must have a non-empty IDType") + } + opts = append(opts, oci.WithWindowsDevice(parts[0], parts[1])) + } } runtime := context.String("runtime")