Skip to content

Commit 17fe1b1

Browse files
committed
add comments and refactor
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 6f1c82b commit 17fe1b1

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package container
1919
import (
2020
"fmt"
2121
"os"
22+
"slices"
2223
"strings"
2324
"testing"
2425

@@ -268,8 +269,8 @@ func TestContainerInspectHostConfig(t *testing.T) {
268269
assert.Equal(t, uint16(500), inspect.HostConfig.BlkioWeight)
269270
assert.Equal(t, uint64(1024), inspect.HostConfig.CPUShares)
270271
assert.Equal(t, int64(100000), inspect.HostConfig.CPUQuota)
271-
assert.Assert(t, contains(inspect.HostConfig.GroupAdd, "1000"), "Expected '1000' to be in GroupAdd")
272-
assert.Assert(t, contains(inspect.HostConfig.GroupAdd, "2000"), "Expected '2000' to be in GroupAdd")
272+
assert.Assert(t, slices.Contains(inspect.HostConfig.GroupAdd, "1000"), "Expected '1000' to be in GroupAdd")
273+
assert.Assert(t, slices.Contains(inspect.HostConfig.GroupAdd, "2000"), "Expected '2000' to be in GroupAdd")
273274
expectedExtraHosts := []string{"host1:10.0.0.1", "host2:10.0.0.2"}
274275
assert.DeepEqual(t, expectedExtraHosts, inspect.HostConfig.ExtraHosts)
275276
assert.Equal(t, "host", inspect.HostConfig.IpcMode)
@@ -288,10 +289,12 @@ func TestContainerInspectHostConfigDefaults(t *testing.T) {
288289

289290
var hc hostConfigValues
290291

292+
// Hostconfig default values differ with Docker.
293+
// This is because we directly retrieve the configured values instead of using preset defaults.
291294
if testutil.GetTarget() == testutil.Docker {
292295
hc.Driver = ""
293296
hc.GroupAddSize = 0
294-
hc.ShmSize = int64(67108864)
297+
hc.ShmSize = int64(67108864) // Docker default 64M
295298
hc.Runtime = "runc"
296299
} else {
297300
hc.GroupAddSize = 10
@@ -453,15 +456,6 @@ func TestContainerInspectDevices(t *testing.T) {
453456
assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
454457
}
455458

456-
func contains(slice []string, item string) bool {
457-
for _, s := range slice {
458-
if s == item {
459-
return true
460-
}
461-
}
462-
return false
463-
}
464-
465459
type hostConfigValues struct {
466460
Driver string
467461
ShmSize int64

pkg/inspecttypes/dockercompat/dockercompat.go

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,48 @@ type Container struct {
138138
// From https://github.com/moby/moby/blob/8dbd90ec00daa26dc45d7da2431c965dec99e8b4/api/types/container/host_config.go#L391
139139
// HostConfig the non-portable Config structure of a container.
140140
type HostConfig struct {
141-
ExtraHosts []string // List of extra hosts
142-
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
143-
LogConfig LoggerLogConfig // Configuration of the logs for this container
144-
BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
145-
CPUSetMems string `json:"CpusetMems"` // CpusetMems 0-2, 0,1
146-
CPUSetCPUs string `json:"CpusetCpus"` // CpusetCpus 0-2, 0,1
147-
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
148-
CPUShares uint64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
149-
ContainerIDFile string // File (path) where the containerId is written
150-
GroupAdd []string // GroupAdd specifies additional groups to join
151-
IpcMode string `json:"IpcMode"` // IPC namespace to use for the container
152-
CgroupnsMode string // Cgroup namespace mode to use for the container
153-
Memory int64 // Memory limit (in bytes)
154-
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
155-
OomKillDisable bool // specifies whether to disable OOM Killer
156-
DNS []string `json:"Dns"` // List of DNS server to lookup
157-
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
158-
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
159-
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
160-
ReadonlyRootfs bool // Is the container root filesystem in read-only
161-
UTSMode string // UTS namespace to use for the container
162-
ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0.
163-
Sysctls map[string]string // List of Namespaced sysctls used for the container
164-
Runtime string // Runtime to use with this container
165-
Devices []DeviceMapping // List of devices to map inside the container
166-
PidMode string // PID namespace to use for the container
167-
Tmpfs map[string]string `json:"Tmpfs,omitempty"` // List of tmpfs (mounts) used for the container
141+
// Binds []string // List of volume bindings for this container
142+
ContainerIDFile string // File (path) where the containerId is written
143+
LogConfig LoggerLogConfig // Configuration of the logs for this container
144+
// NetworkMode NetworkMode // Network mode to use for the container
145+
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
146+
// RestartPolicy RestartPolicy // Restart policy to be used for the container
147+
// AutoRemove bool // Automatically remove container when it exits
148+
// VolumeDriver string // Name of the volume driver used to mount volumes
149+
// VolumesFrom []string // List of volumes to take from other container
150+
// CapAdd strslice.StrSlice // List of kernel capabilities to add to the container
151+
// CapDrop strslice.StrSlice // List of kernel capabilities to remove from the container
152+
153+
CgroupnsMode string // Cgroup namespace mode to use for the container
154+
DNS []string `json:"Dns"` // List of DNS server to lookup
155+
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
156+
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
157+
ExtraHosts []string // List of extra hosts
158+
GroupAdd []string // GroupAdd specifies additional groups to join
159+
IpcMode string `json:"IpcMode"` // IPC namespace to use for the container
160+
// Cgroup CgroupSpec // Cgroup to use for the container
161+
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
162+
PidMode string // PID namespace to use for the container
163+
// Privileged bool // Is the container in privileged mode
164+
// PublishAllPorts bool // Should docker publish all exposed port for the container
165+
ReadonlyRootfs bool // Is the container root filesystem in read-only
166+
// SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux.
167+
Tmpfs map[string]string `json:"Tmpfs,omitempty"` // List of tmpfs (mounts) used for the container
168+
UTSMode string // UTS namespace to use for the container
169+
// UsernsMode UsernsMode // The user namespace to use for the container
170+
ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0.
171+
Sysctls map[string]string // List of Namespaced sysctls used for the container
172+
Runtime string // Runtime to use with this container
173+
174+
BlkioWeight uint16 // Block IO weight (relative weight vs. other containers)
175+
CPUSetMems string `json:"CpusetMems"` // CpusetMems 0-2, 0,1
176+
CPUSetCPUs string `json:"CpusetCpus"` // CpusetCpus 0-2, 0,1
177+
CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota
178+
CPUShares uint64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers)
179+
Memory int64 // Memory limit (in bytes)
180+
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
181+
OomKillDisable bool // specifies whether to disable OOM Killer
182+
Devices []DeviceMapping // List of devices to map inside the container
168183
}
169184

170185
// From https://github.com/moby/moby/blob/v20.10.1/api/types/types.go#L416-L427

pkg/labels/labels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ const (
113113
// HostConfigLabel sets the dockercompat host config values
114114
HostConfigLabel = Prefix + "host-config"
115115

116-
// DNSSettings sets the dockercompat Dns config values
116+
// DNSSettings sets the dockercompat DNS config values
117117
DNSSetting = Prefix + "dns"
118118
)

0 commit comments

Comments
 (0)