Signed-off-by: Antonio Murdaca <runcom@redhat.com>
| ... | ... |
@@ -498,19 +498,23 @@ func (b *Builder) create() (*daemon.Container, error) {
|
| 498 | 498 |
} |
| 499 | 499 |
b.runConfig.Image = b.image |
| 500 | 500 |
|
| 501 |
- // TODO: why not embed a hostconfig in builder? |
|
| 502 |
- hostConfig := &runconfig.HostConfig{
|
|
| 501 |
+ resources := runconfig.Resources{
|
|
| 502 |
+ CgroupParent: b.CgroupParent, |
|
| 503 | 503 |
CPUShares: b.CPUShares, |
| 504 | 504 |
CPUPeriod: b.CPUPeriod, |
| 505 | 505 |
CPUQuota: b.CPUQuota, |
| 506 | 506 |
CpusetCpus: b.CPUSetCpus, |
| 507 | 507 |
CpusetMems: b.CPUSetMems, |
| 508 |
- CgroupParent: b.CgroupParent, |
|
| 509 | 508 |
Memory: b.Memory, |
| 510 | 509 |
MemorySwap: b.MemorySwap, |
| 511 |
- ShmSize: b.ShmSize, |
|
| 512 | 510 |
Ulimits: b.Ulimits, |
| 513 |
- Isolation: b.Isolation, |
|
| 511 |
+ } |
|
| 512 |
+ |
|
| 513 |
+ // TODO: why not embed a hostconfig in builder? |
|
| 514 |
+ hostConfig := &runconfig.HostConfig{
|
|
| 515 |
+ Isolation: b.Isolation, |
|
| 516 |
+ ShmSize: b.ShmSize, |
|
| 517 |
+ Resources: resources, |
|
| 514 | 518 |
} |
| 515 | 519 |
|
| 516 | 520 |
config := *b.runConfig |
| ... | ... |
@@ -22,7 +22,7 @@ func TestAdjustCPUShares(t *testing.T) {
|
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 | 24 |
hostConfig := &runconfig.HostConfig{
|
| 25 |
- CPUShares: linuxMinCPUShares - 1, |
|
| 25 |
+ Resources: runconfig.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 26 | 26 |
} |
| 27 | 27 |
daemon.adaptContainerSettings(hostConfig, true) |
| 28 | 28 |
if hostConfig.CPUShares != linuxMinCPUShares {
|
| ... | ... |
@@ -60,7 +60,7 @@ func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 | 62 |
hostConfig := &runconfig.HostConfig{
|
| 63 |
- CPUShares: linuxMinCPUShares - 1, |
|
| 63 |
+ Resources: runconfig.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 64 | 64 |
} |
| 65 | 65 |
daemon.adaptContainerSettings(hostConfig, false) |
| 66 | 66 |
if hostConfig.CPUShares != linuxMinCPUShares-1 {
|
| ... | ... |
@@ -165,6 +165,28 @@ type LogConfig struct {
|
| 165 | 165 |
Config map[string]string |
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 |
+// Resources contains container's resources (cgroups config, ulimits...) |
|
| 169 |
+type Resources struct {
|
|
| 170 |
+ // Applicable to all platforms |
|
| 171 |
+ CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers) |
|
| 172 |
+ |
|
| 173 |
+ // Applicable to UNIX platforms |
|
| 174 |
+ CgroupParent string // Parent cgroup. |
|
| 175 |
+ BlkioWeight uint16 // Block IO weight (relative weight vs. other containers) |
|
| 176 |
+ BlkioWeightDevice []*blkiodev.WeightDevice |
|
| 177 |
+ CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period |
|
| 178 |
+ CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota |
|
| 179 |
+ CpusetCpus string // CpusetCpus 0-2, 0,1 |
|
| 180 |
+ CpusetMems string // CpusetMems 0-2, 0,1 |
|
| 181 |
+ Devices []DeviceMapping // List of devices to map inside the container |
|
| 182 |
+ KernelMemory int64 // Kernel memory limit (in bytes) |
|
| 183 |
+ Memory int64 // Memory limit (in bytes) |
|
| 184 |
+ MemoryReservation int64 // Memory soft limit (in bytes) |
|
| 185 |
+ MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap |
|
| 186 |
+ MemorySwappiness *int64 // Tuning container memory swappiness behaviour |
|
| 187 |
+ Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container |
|
| 188 |
+} |
|
| 189 |
+ |
|
| 168 | 190 |
// HostConfig the non-portable Config structure of a container. |
| 169 | 191 |
// Here, "non-portable" means "dependent of the host we are running on". |
| 170 | 192 |
// Portable information *should* appear in Config. |
| ... | ... |
@@ -172,7 +194,6 @@ type HostConfig struct {
|
| 172 | 172 |
// Applicable to all platforms |
| 173 | 173 |
Binds []string // List of volume bindings for this container |
| 174 | 174 |
ContainerIDFile string // File (path) where the containerId is written |
| 175 |
- CPUShares int64 `json:"CpuShares"` // CPU shares (relative weight vs. other containers) |
|
| 176 | 175 |
LogConfig LogConfig // Configuration of the logs for this container |
| 177 | 176 |
NetworkMode NetworkMode // Network mode to use for the container |
| 178 | 177 |
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host |
| ... | ... |
@@ -181,41 +202,30 @@ type HostConfig struct {
|
| 181 | 181 |
VolumesFrom []string // List of volumes to take from other container |
| 182 | 182 |
|
| 183 | 183 |
// Applicable to UNIX platforms |
| 184 |
- BlkioWeight uint16 // Block IO weight (relative weight vs. other containers) |
|
| 185 |
- BlkioWeightDevice []*blkiodev.WeightDevice |
|
| 186 |
- CapAdd *stringutils.StrSlice // List of kernel capabilities to add to the container |
|
| 187 |
- CapDrop *stringutils.StrSlice // List of kernel capabilities to remove from the container |
|
| 188 |
- CgroupParent string // Parent cgroup. |
|
| 189 |
- CPUPeriod int64 `json:"CpuPeriod"` // CPU CFS (Completely Fair Scheduler) period |
|
| 190 |
- CPUQuota int64 `json:"CpuQuota"` // CPU CFS (Completely Fair Scheduler) quota |
|
| 191 |
- CpusetCpus string // CpusetCpus 0-2, 0,1 |
|
| 192 |
- CpusetMems string // CpusetMems 0-2, 0,1 |
|
| 193 |
- Devices []DeviceMapping // List of devices to map inside the container |
|
| 194 |
- DNS []string `json:"Dns"` // List of DNS server to lookup |
|
| 195 |
- DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for |
|
| 196 |
- DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for |
|
| 197 |
- ExtraHosts []string // List of extra hosts |
|
| 198 |
- GroupAdd []string // List of additional groups that the container process will run as |
|
| 199 |
- IpcMode IpcMode // IPC namespace to use for the container |
|
| 200 |
- KernelMemory int64 // Kernel memory limit (in bytes) |
|
| 201 |
- Links []string // List of links (in the name:alias form) |
|
| 202 |
- Memory int64 // Memory limit (in bytes) |
|
| 203 |
- MemoryReservation int64 // Memory soft limit (in bytes) |
|
| 204 |
- MemorySwap int64 // Total memory usage (memory + swap); set `-1` to disable swap |
|
| 205 |
- MemorySwappiness *int64 // Tuning container memory swappiness behaviour |
|
| 206 |
- OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 207 |
- PidMode PidMode // PID namespace to use for the container |
|
| 208 |
- Privileged bool // Is the container in privileged mode |
|
| 209 |
- PublishAllPorts bool // Should docker publish all exposed port for the container |
|
| 210 |
- ReadonlyRootfs bool // Is the container root filesystem in read-only |
|
| 211 |
- SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. |
|
| 212 |
- Ulimits []*ulimit.Ulimit // List of ulimits to be set in the container |
|
| 213 |
- UTSMode UTSMode // UTS namespace to use for the container |
|
| 214 |
- ShmSize int64 // Total shm memory usage |
|
| 184 |
+ CapAdd *stringutils.StrSlice // List of kernel capabilities to add to the container |
|
| 185 |
+ CapDrop *stringutils.StrSlice // List of kernel capabilities to remove from the container |
|
| 186 |
+ DNS []string `json:"Dns"` // List of DNS server to lookup |
|
| 187 |
+ DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for |
|
| 188 |
+ DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for |
|
| 189 |
+ ExtraHosts []string // List of extra hosts |
|
| 190 |
+ GroupAdd []string // List of additional groups that the container process will run as |
|
| 191 |
+ IpcMode IpcMode // IPC namespace to use for the container |
|
| 192 |
+ Links []string // List of links (in the name:alias form) |
|
| 193 |
+ OomKillDisable bool // Whether to disable OOM Killer or not |
|
| 194 |
+ PidMode PidMode // PID namespace to use for the container |
|
| 195 |
+ Privileged bool // Is the container in privileged mode |
|
| 196 |
+ PublishAllPorts bool // Should docker publish all exposed port for the container |
|
| 197 |
+ ReadonlyRootfs bool // Is the container root filesystem in read-only |
|
| 198 |
+ SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. |
|
| 199 |
+ UTSMode UTSMode // UTS namespace to use for the container |
|
| 200 |
+ ShmSize int64 // Total shm memory usage |
|
| 215 | 201 |
|
| 216 | 202 |
// Applicable to Windows |
| 217 | 203 |
ConsoleSize [2]int // Initial console size |
| 218 | 204 |
Isolation IsolationLevel // Isolation level of the container (eg default, hyperv) |
| 205 |
+ |
|
| 206 |
+ // Contains container's resources (cgroups, ulimits) |
|
| 207 |
+ Resources |
|
| 219 | 208 |
} |
| 220 | 209 |
|
| 221 | 210 |
// DecodeHostConfig creates a HostConfig based on the specified Reader. |
| ... | ... |
@@ -323,6 +323,24 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 323 | 323 |
return nil, nil, cmd, err |
| 324 | 324 |
} |
| 325 | 325 |
|
| 326 |
+ resources := Resources{
|
|
| 327 |
+ CgroupParent: *flCgroupParent, |
|
| 328 |
+ Memory: flMemory, |
|
| 329 |
+ MemoryReservation: MemoryReservation, |
|
| 330 |
+ MemorySwap: memorySwap, |
|
| 331 |
+ MemorySwappiness: flSwappiness, |
|
| 332 |
+ KernelMemory: KernelMemory, |
|
| 333 |
+ CPUShares: *flCPUShares, |
|
| 334 |
+ CPUPeriod: *flCPUPeriod, |
|
| 335 |
+ CpusetCpus: *flCpusetCpus, |
|
| 336 |
+ CpusetMems: *flCpusetMems, |
|
| 337 |
+ CPUQuota: *flCPUQuota, |
|
| 338 |
+ BlkioWeight: *flBlkioWeight, |
|
| 339 |
+ BlkioWeightDevice: flBlkioWeightDevice.GetList(), |
|
| 340 |
+ Ulimits: flUlimits.GetList(), |
|
| 341 |
+ Devices: deviceMappings, |
|
| 342 |
+ } |
|
| 343 |
+ |
|
| 326 | 344 |
config := &Config{
|
| 327 | 345 |
Hostname: hostname, |
| 328 | 346 |
Domainname: domainname, |
| ... | ... |
@@ -349,25 +367,13 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 349 | 349 |
} |
| 350 | 350 |
|
| 351 | 351 |
hostConfig := &HostConfig{
|
| 352 |
- Binds: binds, |
|
| 353 |
- ContainerIDFile: *flContainerIDFile, |
|
| 354 |
- Memory: flMemory, |
|
| 355 |
- MemoryReservation: MemoryReservation, |
|
| 356 |
- MemorySwap: memorySwap, |
|
| 357 |
- KernelMemory: KernelMemory, |
|
| 358 |
- CPUShares: *flCPUShares, |
|
| 359 |
- CPUPeriod: *flCPUPeriod, |
|
| 360 |
- CpusetCpus: *flCpusetCpus, |
|
| 361 |
- CpusetMems: *flCpusetMems, |
|
| 362 |
- CPUQuota: *flCPUQuota, |
|
| 363 |
- BlkioWeight: *flBlkioWeight, |
|
| 364 |
- BlkioWeightDevice: flBlkioWeightDevice.GetList(), |
|
| 365 |
- OomKillDisable: *flOomKillDisable, |
|
| 366 |
- MemorySwappiness: flSwappiness, |
|
| 367 |
- Privileged: *flPrivileged, |
|
| 368 |
- PortBindings: portBindings, |
|
| 369 |
- Links: flLinks.GetAll(), |
|
| 370 |
- PublishAllPorts: *flPublishAll, |
|
| 352 |
+ Binds: binds, |
|
| 353 |
+ ContainerIDFile: *flContainerIDFile, |
|
| 354 |
+ OomKillDisable: *flOomKillDisable, |
|
| 355 |
+ Privileged: *flPrivileged, |
|
| 356 |
+ PortBindings: portBindings, |
|
| 357 |
+ Links: flLinks.GetAll(), |
|
| 358 |
+ PublishAllPorts: *flPublishAll, |
|
| 371 | 359 |
// Make sure the dns fields are never nil. |
| 372 | 360 |
// New containers don't ever have those fields nil, |
| 373 | 361 |
// but pre created containers can still have those nil values. |
| ... | ... |
@@ -382,19 +388,17 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 382 | 382 |
IpcMode: ipcMode, |
| 383 | 383 |
PidMode: pidMode, |
| 384 | 384 |
UTSMode: utsMode, |
| 385 |
- Devices: deviceMappings, |
|
| 386 | 385 |
CapAdd: stringutils.NewStrSlice(flCapAdd.GetAll()...), |
| 387 | 386 |
CapDrop: stringutils.NewStrSlice(flCapDrop.GetAll()...), |
| 388 | 387 |
GroupAdd: flGroupAdd.GetAll(), |
| 389 | 388 |
RestartPolicy: restartPolicy, |
| 390 | 389 |
SecurityOpt: flSecurityOpt.GetAll(), |
| 391 | 390 |
ReadonlyRootfs: *flReadonlyRootfs, |
| 392 |
- Ulimits: flUlimits.GetList(), |
|
| 393 | 391 |
LogConfig: LogConfig{Type: *flLoggingDriver, Config: loggingOpts},
|
| 394 |
- CgroupParent: *flCgroupParent, |
|
| 395 | 392 |
VolumeDriver: *flVolumeDriver, |
| 396 | 393 |
Isolation: IsolationLevel(*flIsolation), |
| 397 | 394 |
ShmSize: parsedShm, |
| 395 |
+ Resources: resources, |
|
| 398 | 396 |
} |
| 399 | 397 |
|
| 400 | 398 |
// When allocating stdin in attached mode, close stdin at client disconnect |