Skip to content

Commit c2732d5

Browse files
committed
fix parseDevices import
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 3fd2f33 commit c2732d5

File tree

4 files changed

+41
-47
lines changed

4 files changed

+41
-47
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -322,37 +322,37 @@ jobs:
322322
- name: "build"
323323
run: GO_VERSION="$(echo ${{ matrix.go-version }} | sed -e s/.x//)" make binaries
324324

325-
# test-integration-docker-compatibility:
326-
# timeout-minutes: 30
327-
# name: docker
328-
# runs-on: ubuntu-24.04
329-
# steps:
330-
# - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
331-
# with:
332-
# fetch-depth: 1
333-
# - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
334-
# with:
335-
# go-version: ${{ env.GO_VERSION }}
336-
# check-latest: true
337-
# - name: "Register QEMU (tonistiigi/binfmt)"
338-
# run: |
339-
# # `--install all` will only install emulation for architectures that cannot be natively executed
340-
# # Since some arm64 platforms do provide native fallback execution for 32 bits,
341-
# # armv7 emulation may or may not be installed, causing variance in the result of `uname -m`.
342-
# # To avoid that, we explicitly list the architectures we do want emulation for.
343-
# docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
344-
# docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
345-
# docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
346-
# - name: "Prepare integration test environment"
347-
# run: |
348-
# sudo apt-get install -y expect
349-
# go install -v gotest.tools/gotestsum@v1
350-
# - name: "Ensure that the integration test suite is compatible with Docker"
351-
# run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker
352-
# - name: "Ensure that the IPv6 integration test suite is compatible with Docker"
353-
# run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker -test.only-ipv6
354-
# - name: "Ensure that the integration test suite is compatible with Docker (flaky only)"
355-
# run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker -test.only-flaky
325+
test-integration-docker-compatibility:
326+
timeout-minutes: 30
327+
name: docker
328+
runs-on: ubuntu-24.04
329+
steps:
330+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
331+
with:
332+
fetch-depth: 1
333+
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
334+
with:
335+
go-version: ${{ env.GO_VERSION }}
336+
check-latest: true
337+
- name: "Register QEMU (tonistiigi/binfmt)"
338+
run: |
339+
# `--install all` will only install emulation for architectures that cannot be natively executed
340+
# Since some arm64 platforms do provide native fallback execution for 32 bits,
341+
# armv7 emulation may or may not be installed, causing variance in the result of `uname -m`.
342+
# To avoid that, we explicitly list the architectures we do want emulation for.
343+
docker run --privileged --rm tonistiigi/binfmt --install linux/amd64
344+
docker run --privileged --rm tonistiigi/binfmt --install linux/arm64
345+
docker run --privileged --rm tonistiigi/binfmt --install linux/arm/v7
346+
- name: "Prepare integration test environment"
347+
run: |
348+
sudo apt-get install -y expect
349+
go install -v gotest.tools/gotestsum@v1
350+
- name: "Ensure that the integration test suite is compatible with Docker"
351+
run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker
352+
- name: "Ensure that the IPv6 integration test suite is compatible with Docker"
353+
run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker -test.only-ipv6
354+
- name: "Ensure that the integration test suite is compatible with Docker (flaky only)"
355+
run: WITH_SUDO=true ./hack/test-integration.sh -test.target=docker -test.only-flaky
356356

357357
test-integration-windows:
358358
timeout-minutes: 30

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ func TestContainerInspectHostConfigPID(t *testing.T) {
363363
// Run the first container
364364
base.Cmd("run", "-d", "--name", testContainer1, testutil.AlpineImage, "sleep", "infinity").AssertOK()
365365

366-
container1_ID := strings.TrimSpace(base.Cmd("inspect", "-f", "{{.Id}}", testContainer1).Out())
366+
containerId1 := strings.TrimSpace(base.Cmd("inspect", "-f", "{{.Id}}", testContainer1).Out())
367367

368368
base.Cmd("run", "-d", "--name", testContainer2,
369369
"--pid", fmt.Sprintf("container:%s", testContainer1),
370370
testutil.AlpineImage, "sleep", "infinity").AssertOK()
371371

372372
inspect := base.InspectContainer(testContainer2)
373373

374-
assert.Equal(t, fmt.Sprintf("container:%s", container1_ID), inspect.HostConfig.PidMode)
374+
assert.Equal(t, fmt.Sprintf("container:%s", containerId1), inspect.HostConfig.PidMode)
375375

376376
}
377377

pkg/cmd/container/create.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ type internalLabels struct {
663663
groupAdd []string
664664

665665
// label for device mapping set by the --device flag
666-
deviceMapping []string
666+
deviceMapping []dockercompat.DeviceMapping
667667
}
668668

669669
// WithInternalLabels sets the internal labels for a container.
@@ -773,18 +773,7 @@ func withInternalLabels(internalLabels internalLabels) (containerd.NewContainerO
773773
}
774774

775775
if len(internalLabels.deviceMapping) > 0 {
776-
for i := range internalLabels.deviceMapping {
777-
var deviceMapping dockercompat.DeviceMapping
778-
device := internalLabels.deviceMapping[i]
779-
devPath, conPath, mode, err := ParseDevice(device)
780-
if err != nil {
781-
return nil, err
782-
}
783-
deviceMapping.CgroupPermissions = mode
784-
deviceMapping.PathInContainer = conPath
785-
deviceMapping.PathOnHost = devPath
786-
hostConfigLabel.Devices = append(hostConfigLabel.Devices, deviceMapping)
787-
}
776+
hostConfigLabel.Devices = append(hostConfigLabel.Devices, internalLabels.deviceMapping...)
788777
}
789778

790779
hostConfigJSON, err := json.Marshal(hostConfigLabel)

pkg/cmd/container/run_cgroup_linux.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232

3333
"github.com/containerd/nerdctl/v2/pkg/api/types"
3434
"github.com/containerd/nerdctl/v2/pkg/infoutil"
35+
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
3536
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3637
)
3738

@@ -206,7 +207,11 @@ func generateCgroupOpts(id string, options types.ContainerCreateOptions, interna
206207
return nil, fmt.Errorf("failed to parse device %q: %w", f, err)
207208
}
208209
opts = append(opts, oci.WithDevices(devPath, conPath, mode))
209-
internalLabels.deviceMapping = append(internalLabels.deviceMapping, f)
210+
var deviceMap dockercompat.DeviceMapping
211+
deviceMap.PathOnHost = devPath
212+
deviceMap.PathInContainer = conPath
213+
deviceMap.CgroupPermissions = mode
214+
internalLabels.deviceMapping = append(internalLabels.deviceMapping, deviceMap)
210215
}
211216

212217
return opts, nil

0 commit comments

Comments
 (0)