Skip to content

Commit

Permalink
Merge pull request #2079 from adamrehn/windows-device-support
Browse files Browse the repository at this point in the history
Port Windows device support from containerd
  • Loading branch information
fahedouch committed Mar 19, 2023
2 parents 5d5b848 + 3effa44 commit 05a7c66
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cmd/nerdctl/container_run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package main

import (
"context"
"errors"
"fmt"
"strings"

"github.com/containerd/containerd"
"github.com/containerd/containerd/containers"
Expand Down Expand Up @@ -132,6 +134,22 @@ func setPlatformOptions(
oci.WithWindowNetworksAllowUnqualifiedDNSQuery(),
oci.WithWindowsIgnoreFlushesDuringBoot())

device, err := cmd.Flags().GetStringSlice("device")
if err != nil {
return nil, err
}

for _, dev := range device {
idType, devID, ok := strings.Cut(dev, "://")
if !ok {
return nil, errors.New("devices must be in the format IDType://ID")
}
if idType == "" {
return nil, errors.New("devices must have a non-empty IDType")
}
opts = append(opts, oci.WithWindowsDevice(idType, devID))
}

return opts, nil
}

Expand Down
17 changes: 17 additions & 0 deletions cmd/nerdctl/container_run_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,20 @@ func TestRunProcessContainer(t *testing.T) {

assert.Assert(t, !strings.Contains(inspectOutput, "hyperv"))
}

// Note that the current implementation of this test is not ideal, since it relies on internal HCS details that
// Microsoft could decide to change in the future (breaking both this unit test and the one in containerd itself):
// https://github.com/containerd/containerd/pull/6618#discussion_r823302852
func TestRunProcessContainerWithDevice(t *testing.T) {
testutil.DockerIncompatible(t)
base := testutil.NewBase(t)

base.Cmd(
"run",
"--rm",
"--isolation=process",
"--device", "class://5B45201D-F2F2-4F3B-85BB-30FF1F953599",
testutil.WindowsNano,
"cmd", "/S", "/C", "dir C:\\Windows\\System32\\HostDriverStore",
).AssertOutContains("FileRepository")
}
2 changes: 1 addition & 1 deletion docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Resource flags:
- :whale: `--cgroupns=(host|private)`: Cgroup namespace to use
- Default: "private" on cgroup v2 hosts, "host" on cgroup v1 hosts
- :whale: `--cgroup-parent`: Optional parent cgroup for the container
- :whale: `--device`: Add a host device to the container
- :whale: :blue_square: `--device`: Add a host device to the container

Intel RDT flags:

Expand Down

0 comments on commit 05a7c66

Please sign in to comment.