Skip to content

Commit b0a9fb5

Browse files
committed
chore: add runtime and sysctl to inspect response
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 3b9fa16 commit b0a9fb5

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ func TestContainerInspectHostConfig(t *testing.T) {
253253
"--read-only",
254254
"--uts", "host",
255255
"--shm-size", "256m",
256+
"--runtime", "io.containerd.runtime.v1.linux",
257+
"--sysctl", "net.core.somaxconn=1024",
256258
testutil.AlpineImage, "sleep", "infinity").AssertOK()
257259

258260
inspect := base.InspectContainer(testContainer)
@@ -274,6 +276,11 @@ func TestContainerInspectHostConfig(t *testing.T) {
274276
assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
275277
assert.Equal(t, "host", inspect.HostConfig.UTSMode)
276278
assert.Equal(t, int64(268435456), inspect.HostConfig.ShmSize)
279+
assert.Equal(t, "io.containerd.runtime.v1.linux", inspect.HostConfig.Runtime)
280+
expectedSysctls := map[string]string{
281+
"net.core.somaxconn": "1024",
282+
}
283+
assert.DeepEqual(t, expectedSysctls, inspect.HostConfig.Sysctls)
277284
}
278285

279286
func TestContainerInspectHostConfigDefaults(t *testing.T) {
@@ -302,6 +309,8 @@ func TestContainerInspectHostConfigDefaults(t *testing.T) {
302309
assert.Equal(t, false, inspect.HostConfig.ReadonlyRootfs)
303310
assert.Equal(t, "", inspect.HostConfig.UTSMode)
304311
assert.Equal(t, int64(67108864), inspect.HostConfig.ShmSize)
312+
assert.Equal(t, "io.containerd.runc.v2", inspect.HostConfig.Runtime)
313+
assert.Equal(t, 0, len(inspect.HostConfig.Sysctls))
305314
}
306315

307316
func TestContainerInspectHostConfigDNS(t *testing.T) {

pkg/inspecttypes/dockercompat/dockercompat.go

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,30 @@ type Container struct {
143143
// From https://github.com/moby/moby/blob/8dbd90ec00daa26dc45d7da2431c965dec99e8b4/api/types/container/host_config.go#L391
144144
// HostConfig the non-portable Config structure of a container.
145145
type HostConfig struct {
146-
ExtraHosts []string // List of extra hosts
147-
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
148-
LogConfig LogConfig // Configuration of the logs for this container
149-
BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
150-
CPUSetMems string `json:"CpusetMems"` // CpusetMems 0-2, 0,1
151-
CPUSetCPUs string `json:"CpusetCpus"` // CpusetCpus 0-2, 0,1
152-
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
153-
CPUShares uint64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
154-
ContainerIDFile string // File (path) where the containerId is written
155-
GroupAdd []string // GroupAdd specifies additional groups to join
156-
IpcMode string // IPC namespace to use for the container
157-
CgroupnsMode string // Cgroup namespace mode to use for the container
158-
Memory int64 // Memory limit (in bytes)
159-
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
160-
OomKillDisable bool // specifies whether to disable OOM Killer
161-
DNS []string `json:"Dns"` // List of DNS server to lookup
162-
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
163-
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
164-
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
165-
ReadonlyRootfs bool // Is the container root filesystem in read-only
166-
UTSMode string // UTS namespace to use for the container
167-
ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0.
168-
146+
ExtraHosts []string // List of extra hosts
147+
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
148+
LogConfig LogConfig // Configuration of the logs for this container
149+
BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
150+
CPUSetMems string `json:"CpusetMems"` // CpusetMems 0-2, 0,1
151+
CPUSetCPUs string `json:"CpusetCpus"` // CpusetCpus 0-2, 0,1
152+
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
153+
CPUShares uint64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
154+
ContainerIDFile string // File (path) where the containerId is written
155+
GroupAdd []string // GroupAdd specifies additional groups to join
156+
IpcMode string // IPC namespace to use for the container
157+
CgroupnsMode string // Cgroup namespace mode to use for the container
158+
Memory int64 // Memory limit (in bytes)
159+
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
160+
OomKillDisable bool // specifies whether to disable OOM Killer
161+
DNS []string `json:"Dns"` // List of DNS server to lookup
162+
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
163+
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
164+
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
165+
ReadonlyRootfs bool // Is the container root filesystem in read-only
166+
UTSMode string // UTS namespace to use for the container
167+
ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0.
168+
Sysctls map[string]string // List of Namespaced sysctls used for the container
169+
Runtime string // Runtime to use with this container
169170
}
170171

171172
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427
@@ -466,6 +467,13 @@ func ContainerFromNative(n *native.Container) (*Container, error) {
466467
shmSize, _ := getShmSizeFromNative(n.Spec.(*specs.Spec))
467468
c.HostConfig.ShmSize = shmSize
468469

470+
sysctls, _ := getSysctlFromNative(n.Spec.(*specs.Spec))
471+
c.HostConfig.Sysctls = sysctls
472+
473+
if n.Runtime.Name != "" {
474+
c.HostConfig.Runtime = n.Runtime.Name
475+
}
476+
469477
c.State = cs
470478
c.Config = &Config{
471479
Labels: n.Labels,
@@ -789,6 +797,14 @@ func getShmSizeFromNative(sp *specs.Spec) (int64, error) {
789797
return res, nil
790798
}
791799

800+
func getSysctlFromNative(sp *specs.Spec) (map[string]string, error) {
801+
var res map[string]string
802+
if sp.Linux != nil && sp.Linux.Sysctl != nil {
803+
res = sp.Linux.Sysctl
804+
}
805+
return res, nil
806+
}
807+
792808
type IPAMConfig struct {
793809
Subnet string `json:"Subnet,omitempty"`
794810
Gateway string `json:"Gateway,omitempty"`

0 commit comments

Comments
 (0)