1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Windows: Refactor resources structure

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2015-10-05 10:11:10 -07:00
parent e252fe288c
commit b1220a763c
7 changed files with 56 additions and 40 deletions

View file

@ -279,19 +279,21 @@ func populateCommand(c *Container, env []string) error {
} }
resources := &execdriver.Resources{ resources := &execdriver.Resources{
Memory: c.hostConfig.Memory, CommonResources: execdriver.CommonResources{
MemorySwap: c.hostConfig.MemorySwap, Memory: c.hostConfig.Memory,
MemoryReservation: c.hostConfig.MemoryReservation, MemoryReservation: c.hostConfig.MemoryReservation,
KernelMemory: c.hostConfig.KernelMemory, CPUShares: c.hostConfig.CPUShares,
CPUShares: c.hostConfig.CPUShares, BlkioWeight: c.hostConfig.BlkioWeight,
CpusetCpus: c.hostConfig.CpusetCpus, },
CpusetMems: c.hostConfig.CpusetMems, MemorySwap: c.hostConfig.MemorySwap,
CPUPeriod: c.hostConfig.CPUPeriod, KernelMemory: c.hostConfig.KernelMemory,
CPUQuota: c.hostConfig.CPUQuota, CpusetCpus: c.hostConfig.CpusetCpus,
BlkioWeight: c.hostConfig.BlkioWeight, CpusetMems: c.hostConfig.CpusetMems,
Rlimits: rlimits, CPUPeriod: c.hostConfig.CPUPeriod,
OomKillDisable: c.hostConfig.OomKillDisable, CPUQuota: c.hostConfig.CPUQuota,
MemorySwappiness: -1, Rlimits: rlimits,
OomKillDisable: c.hostConfig.OomKillDisable,
MemorySwappiness: -1,
} }
if c.hostConfig.MemorySwappiness != nil { if c.hostConfig.MemorySwappiness != nil {

View file

@ -86,7 +86,9 @@ func populateCommand(c *Container, env []string) error {
// TODO Windows. More resource controls to be implemented later. // TODO Windows. More resource controls to be implemented later.
resources := &execdriver.Resources{ resources := &execdriver.Resources{
CPUShares: c.hostConfig.CPUShares, CommonResources: execdriver.CommonResources{
CPUShares: c.hostConfig.CPUShares,
},
} }
// TODO Windows. Further refactoring required (privileged/user) // TODO Windows. Further refactoring required (privileged/user)

View file

@ -7,8 +7,6 @@ import (
"time" "time"
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
// TODO Windows: Factor out ulimit
"github.com/docker/docker/pkg/ulimit"
"github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
) )
@ -138,23 +136,13 @@ type UTS struct {
HostUTS bool `json:"host_uts"` HostUTS bool `json:"host_uts"`
} }
// Resources contains all resource configs for a driver. // CommonResources contains the resource configs for a driver that are
// Currently these are all for cgroup configs. // common across platforms.
// TODO Windows: Factor out ulimit.Rlimit type CommonResources struct {
type Resources struct { Memory int64 `json:"memory"`
Memory int64 `json:"memory"` MemoryReservation int64 `json:"memory_reservation"`
MemorySwap int64 `json:"memory_swap"` CPUShares int64 `json:"cpu_shares"`
MemoryReservation int64 `json:"memory_reservation"` BlkioWeight uint16 `json:"blkio_weight"`
KernelMemory int64 `json:"kernel_memory"`
CPUShares int64 `json:"cpu_shares"`
CpusetCpus string `json:"cpuset_cpus"`
CpusetMems string `json:"cpuset_mems"`
CPUPeriod int64 `json:"cpu_period"`
CPUQuota int64 `json:"cpu_quota"`
BlkioWeight uint16 `json:"blkio_weight"`
Rlimits []*ulimit.Rlimit `json:"rlimits"`
OomKillDisable bool `json:"oom_kill_disable"`
MemorySwappiness int64 `json:"memory_swappiness"`
} }
// ResourceStats contains information about resource usage by a container. // ResourceStats contains information about resource usage by a container.

View file

@ -13,6 +13,7 @@ import (
"github.com/docker/docker/daemon/execdriver/native/template" "github.com/docker/docker/daemon/execdriver/native/template"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/ulimit"
"github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/cgroups/fs" "github.com/opencontainers/runc/libcontainer/cgroups/fs"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
@ -27,6 +28,24 @@ type Mount struct {
Slave bool `json:"slave"` Slave bool `json:"slave"`
} }
// Resources contains all resource configs for a driver.
// Currently these are all for cgroup configs.
type Resources struct {
CommonResources
// Fields below here are platform specific
MemorySwap int64 `json:"memory_swap"`
KernelMemory int64 `json:"kernel_memory"`
CPUQuota int64 `json:"cpu_quota"`
CpusetCpus string `json:"cpuset_cpus"`
CpusetMems string `json:"cpuset_mems"`
CPUPeriod int64 `json:"cpu_period"`
Rlimits []*ulimit.Rlimit `json:"rlimits"`
OomKillDisable bool `json:"oom_kill_disable"`
MemorySwappiness int64 `json:"memory_swappiness"`
}
// Network settings of the container // Network settings of the container
type Network struct { type Network struct {
Mtu int `json:"mtu"` Mtu int `json:"mtu"`

View file

@ -9,6 +9,14 @@ type Mount struct {
Writable bool `json:"writable"` Writable bool `json:"writable"`
} }
// Resources contains all resource configs for a driver.
// Currently these are all for cgroup configs.
type Resources struct {
CommonResources
// Fields below here are platform specific
}
// Network settings of the container // Network settings of the container
type Network struct { type Network struct {
Interface *NetworkInterface `json:"interface"` Interface *NetworkInterface `json:"interface"`

View file

@ -47,9 +47,11 @@ func TestLXCConfig(t *testing.T) {
command := &execdriver.Command{ command := &execdriver.Command{
ID: "1", ID: "1",
Resources: &execdriver.Resources{ Resources: &execdriver.Resources{
Memory: int64(mem),
MemorySwap: int64(swap), MemorySwap: int64(swap),
CPUShares: int64(cpu), CommonResources: execdriver.CommonResources{
Memory: int64(mem),
CPUShares: int64(cpu),
},
}, },
Network: &execdriver.Network{ Network: &execdriver.Network{
Mtu: 1500, Mtu: 1500,

View file

@ -24,11 +24,6 @@ func checkSupportedOptions(c *execdriver.Command) error {
return errors.New("Windows does not support lxc options") return errors.New("Windows does not support lxc options")
} }
// Windows doesn't support ulimit
if c.Resources.Rlimits != nil {
return errors.New("Windows does not support ulimit options")
}
// TODO Windows: Validate other fields which Windows doesn't support, factor // TODO Windows: Validate other fields which Windows doesn't support, factor
// out where applicable per platform. // out where applicable per platform.