2016-03-18 18:50:19 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-02-18 06:04:37 +00:00
|
|
|
"time"
|
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-03-18 18:50:19 +00:00
|
|
|
"github.com/docker/docker/libcontainerd"
|
2017-09-22 13:52:41 +00:00
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
func toContainerdResources(resources container.Resources) *libcontainerd.Resources {
|
2016-03-18 18:50:19 +00:00
|
|
|
var r libcontainerd.Resources
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
r.BlockIO = &specs.LinuxBlockIO{
|
|
|
|
Weight: &resources.BlkioWeight,
|
|
|
|
}
|
|
|
|
|
|
|
|
shares := uint64(resources.CPUShares)
|
|
|
|
r.CPU = &specs.LinuxCPU{
|
|
|
|
Shares: &shares,
|
|
|
|
Cpus: resources.CpusetCpus,
|
|
|
|
Mems: resources.CpusetMems,
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
period uint64
|
|
|
|
quota int64
|
|
|
|
)
|
2017-02-18 06:04:37 +00:00
|
|
|
if resources.NanoCPUs != 0 {
|
2017-09-22 13:52:41 +00:00
|
|
|
period = uint64(100 * time.Millisecond / time.Microsecond)
|
|
|
|
quota = resources.NanoCPUs * int64(period) / 1e9
|
2017-02-18 06:04:37 +00:00
|
|
|
}
|
2018-01-16 16:35:04 +00:00
|
|
|
if quota == 0 && resources.CPUQuota != 0 {
|
|
|
|
quota = resources.CPUQuota
|
|
|
|
}
|
|
|
|
if period == 0 && resources.CPUPeriod != 0 {
|
|
|
|
period = uint64(resources.CPUPeriod)
|
|
|
|
}
|
|
|
|
|
2017-09-22 13:52:41 +00:00
|
|
|
r.CPU.Period = &period
|
|
|
|
r.CPU.Quota = "a
|
|
|
|
|
|
|
|
r.Memory = &specs.LinuxMemory{
|
|
|
|
Limit: &resources.Memory,
|
|
|
|
Reservation: &resources.MemoryReservation,
|
|
|
|
Kernel: &resources.KernelMemory,
|
|
|
|
}
|
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
if resources.MemorySwap > 0 {
|
2017-09-22 13:52:41 +00:00
|
|
|
r.Memory.Swap = &resources.MemorySwap
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
2017-09-22 13:52:41 +00:00
|
|
|
|
|
|
|
return &r
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|