Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
99acf7f
feat: add hostConfig to nerdctl inspect response
coderbirju Jan 2, 2025
cfdf044
fix: add loggerLogConfig
coderbirju Jan 3, 2025
44e2c75
chore: add CIdFile and GroupAdd to nerdctl inspect response
coderbirju Jan 16, 2025
fbd4fa1
chore: use native inspect instead of labels
coderbirju Jan 17, 2025
0395ab7
chore: add tests
coderbirju Jan 17, 2025
bf18a4a
chore: add Memory and CgroupNsMode
coderbirju Jan 19, 2025
70b8975
chore: add dns config to inspect response
coderbirju Jan 20, 2025
48d15e1
chore: add oomScoreAdj to inspect response
coderbirju Jan 20, 2025
6dbf0c5
chore: add ReadonlyRootfs,UTSMode,ShmSize to inspect response
coderbirju Jan 20, 2025
a304a27
chore: add runtime and sysctl to inspect response
coderbirju Jan 21, 2025
42c33cc
chore: fix logConfig inspect response
coderbirju Jan 21, 2025
f98666e
chore: add device to inspect response
coderbirju Jan 21, 2025
a71684a
chore: refactor inspect response
coderbirju Jan 22, 2025
64ad424
chore: add pidMode to inspect response
coderbirju Jan 22, 2025
714feda
fix errors
coderbirju Jan 24, 2025
e640350
identify errors
coderbirju Jan 24, 2025
f0ebe0d
Merge branch 'main' into add-hostconfig-inspect-dirty
coderbirju Jan 24, 2025
a3d1e7e
identify errors 2
coderbirju Jan 24, 2025
916a9c9
fix errors 1
coderbirju Jan 24, 2025
821ea3d
id errors 3
coderbirju Jan 24, 2025
a131c4d
id errors 4
coderbirju Jan 24, 2025
7f18572
id errors 5
coderbirju Jan 24, 2025
b536c38
id errors 6
coderbirju Jan 24, 2025
92ebc28
fix tmpfs errors?
coderbirju Jan 24, 2025
92a7a5b
add back options?
coderbirju Jan 24, 2025
889bc96
fix deviceMapping
coderbirju Jan 25, 2025
6ecffe0
id more errors
coderbirju Jan 25, 2025
858af64
test systcl flag
coderbirju Jan 25, 2025
8954875
test --runtime
coderbirju Jan 25, 2025
6304ad1
test defaults
coderbirju Jan 25, 2025
3fd2f33
test devices
coderbirju Jan 26, 2025
c2732d5
fix parseDevices import
coderbirju Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
target: rootless
arch: amd64
- ubuntu: 22.04
containerd: v1.7.25
containerd: v1.7.24
rootlesskit: v2.3.1
target: rootless
arch: amd64
Expand All @@ -244,7 +244,7 @@ jobs:
target: rootless
arch: amd64
- ubuntu: 24.04
containerd: v1.7.25
containerd: v1.7.24
rootlesskit: v2.3.1
target: rootless-port-slirp4netns
arch: amd64
Expand All @@ -260,7 +260,7 @@ jobs:
run: |
cat <<EOT | sudo tee "/etc/apparmor.d/usr.local.bin.rootlesskit"
abi <abi/4.0>,
include <tunables/global>


/usr/local/bin/rootlesskit flags=(unconfined) {
userns,
Expand Down Expand Up @@ -374,21 +374,22 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
repository: containerd/containerd
ref: v1.7.25
ref: v1.7.24
path: containerd
fetch-depth: 1
- name: "Set up CNI"
working-directory: containerd
run: GOPATH=$(go env GOPATH) script/setup/install-cni-windows
- name: "Set up containerd"
env:
ctrdVersion: 1.7.25
ctrdVersion: 1.7.24
run: powershell hack/configure-windows-ci.ps1
- name: "Run integration tests"
run: ./hack/test-integration.sh -test.only-flaky=false
- name: "Run integration tests (flaky)"
run: ./hack/test-integration.sh -test.only-flaky=true


test-integration-freebsd:
timeout-minutes: 30
name: FreeBSD
Expand Down
184 changes: 182 additions & 2 deletions cmd/nerdctl/container/container_inspect_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@
testutil.NginxAlpineImage).AssertOK()

inspect := base.InspectContainer(testContainer)

// convert array to map to get by key of Destination
actual := make(map[string]dockercompat.MountPoint)
for i := range inspect.Mounts {
actual[inspect.Mounts[i].Destination] = inspect.Mounts[i]
}

t.Logf("actual in TestContainerInspectContainsMounts: %+v", actual)
const localDriver = "local"

expected := []struct {
Expand Down Expand Up @@ -229,3 +228,184 @@
}

}

func TestContainerInspectHostConfig(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

// Run a container with various HostConfig options
base.Cmd("run", "-d", "--name", testContainer,
"--cpuset-cpus", "0-1",
"--cpuset-mems", "0",
"--blkio-weight", "500",
"--cpu-shares", "1024",
"--cpu-quota", "100000",
"--group-add", "1000",
"--group-add", "2000",
"--add-host", "host1:10.0.0.1",
"--add-host", "host2:10.0.0.2",
"--ipc", "host",
"--memory", "512m",
"--read-only",
"--shm-size", "256m",
"--uts", "host",
"--sysctl", "net.core.somaxconn=1024",
"--runtime", "io.containerd.runc.v2",
testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)

assert.Equal(t, "0-1", inspect.HostConfig.CPUSetCPUs)
assert.Equal(t, "0", inspect.HostConfig.CPUSetMems)
assert.Equal(t, uint16(500), inspect.HostConfig.BlkioWeight)
assert.Equal(t, uint64(1024), inspect.HostConfig.CPUShares)
assert.Equal(t, int64(100000), inspect.HostConfig.CPUQuota)
assert.DeepEqual(t, []string{"1000", "2000"}, inspect.HostConfig.GroupAdd)
expectedExtraHosts := []string{"host1:10.0.0.1", "host2:10.0.0.2"}
assert.DeepEqual(t, expectedExtraHosts, inspect.HostConfig.ExtraHosts)
assert.Equal(t, "host", inspect.HostConfig.IpcMode)
assert.Equal(t, "", inspect.HostConfig.LogConfig.Driver)
assert.Equal(t, int64(536870912), inspect.HostConfig.Memory)
assert.Equal(t, int64(1073741824), inspect.HostConfig.MemorySwap)
assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
assert.Equal(t, "host", inspect.HostConfig.UTSMode)
assert.Equal(t, int64(268435456), inspect.HostConfig.ShmSize)
}

func TestContainerInspectHostConfigDefaults(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

// Run a container without specifying HostConfig options
base.Cmd("run", "-d", "--name", testContainer, testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)
t.Logf("HostConfig in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig)
assert.Equal(t, "", inspect.HostConfig.CPUSetCPUs)
assert.Equal(t, "", inspect.HostConfig.CPUSetMems)
assert.Equal(t, uint16(0), inspect.HostConfig.BlkioWeight)
assert.Equal(t, uint64(0), inspect.HostConfig.CPUShares)
assert.Equal(t, int64(0), inspect.HostConfig.CPUQuota)
assert.Equal(t, 0, len(inspect.HostConfig.GroupAdd))
assert.Equal(t, 0, len(inspect.HostConfig.ExtraHosts))
assert.Equal(t, "private", inspect.HostConfig.IpcMode)
assert.Equal(t, "", inspect.HostConfig.LogConfig.Driver)
assert.Equal(t, int64(0), inspect.HostConfig.Memory)
assert.Equal(t, int64(0), inspect.HostConfig.MemorySwap)
assert.Equal(t, bool(false), inspect.HostConfig.OomKillDisable)
assert.Equal(t, bool(false), inspect.HostConfig.ReadonlyRootfs)
assert.Equal(t, "", inspect.HostConfig.UTSMode)
assert.Equal(t, int64(67108864), inspect.HostConfig.ShmSize)
assert.Equal(t, "runc", inspect.HostConfig.Runtime)
assert.Equal(t, 0, len(inspect.HostConfig.Sysctls))
assert.Equal(t, 0, len(inspect.HostConfig.Devices))
}

func TestContainerInspectHostConfigDNS(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

// Run a container with DNS options
base.Cmd("run", "-d", "--name", testContainer,
"--dns", "8.8.8.8",
"--dns", "1.1.1.1",
"--dns-search", "example.com",
"--dns-search", "test.local",
"--dns-option", "ndots:5",
"--dns-option", "timeout:3",
testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)

// Check DNS servers
expectedDNSServers := []string{"8.8.8.8", "1.1.1.1"}
assert.DeepEqual(t, expectedDNSServers, inspect.HostConfig.DNS)

// Check DNS search domains
expectedDNSSearch := []string{"example.com", "test.local"}
assert.DeepEqual(t, expectedDNSSearch, inspect.HostConfig.DNSSearch)

// Check DNS options
expectedDNSOptions := []string{"ndots:5", "timeout:3"}
assert.DeepEqual(t, expectedDNSOptions, inspect.HostConfig.DNSOptions)
}

func TestContainerInspectHostConfigDNSDefaults(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

// Run a container without specifying DNS options
base.Cmd("run", "-d", "--name", testContainer, testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)

// Check that DNS settings are empty by default
assert.Equal(t, 0, len(inspect.HostConfig.DNS))
assert.Equal(t, 0, len(inspect.HostConfig.DNSSearch))
assert.Equal(t, 0, len(inspect.HostConfig.DNSOptions))
}

func TestContainerInspectHostConfigPID(t *testing.T) {
testContainer1 := testutil.Identifier(t) + "-container1"
testContainer2 := testutil.Identifier(t) + "-container2"

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer1, testContainer2).Run()

// Run the first container
base.Cmd("run", "-d", "--name", testContainer1, testutil.AlpineImage, "sleep", "infinity").AssertOK()

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

Check failure on line 366 in cmd/nerdctl/container/container_inspect_linux_test.go

View workflow job for this annotation

GitHub Actions / go | linux |

var-naming: var containerId1 should be containerID1 (revive)

Check failure on line 366 in cmd/nerdctl/container/container_inspect_linux_test.go

View workflow job for this annotation

GitHub Actions / go | linux | go-canary

var-naming: var containerId1 should be containerID1 (revive)

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

inspect := base.InspectContainer(testContainer2)

assert.Equal(t, fmt.Sprintf("container:%s", containerId1), inspect.HostConfig.PidMode)

}

func TestContainerInspectHostConfigPIDDefaults(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

base.Cmd("run", "-d", "--name", testContainer, testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)

assert.Equal(t, "", inspect.HostConfig.PidMode)
}

func TestContainerInspectDevices(t *testing.T) {
testContainer := testutil.Identifier(t)

base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

base.Cmd("run", "-d", "--name", testContainer,
"--device", "/dev/null:/dev/null",
testutil.AlpineImage, "sleep", "infinity").AssertOK()

inspect := base.InspectContainer(testContainer)

expectedDevices := []dockercompat.DeviceMapping{
{
PathOnHost: "/dev/null",
PathInContainer: "/dev/null",
CgroupPermissions: "rwm",
},
}
assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
}
Loading
Loading