f5209d23a8
This adds some nolint-comments for the deprecated kernel-memory options; we deprecated these, but they could technically still be accepted by alternative runtimes. daemon/daemon_unix.go:108:3: SA1019: memory.Kernel is deprecated: kernel-memory limits are not supported in cgroups v2, and were obsoleted in [kernel v5.4]. This field should no longer be used, as it may be ignored by runtimes. (staticcheck) memory.Kernel = &config.KernelMemory ^ daemon/update_linux.go:63:3: SA1019: memory.Kernel is deprecated: kernel-memory limits are not supported in cgroups v2, and were obsoleted in [kernel v5.4]. This field should no longer be used, as it may be ignored by runtimes. (staticcheck) memory.Kernel = &resources.KernelMemory ^ Prestart hooks are deprecated, and more granular hooks should be used instead. CreateRuntime are the closest equivalent, and executed in the same locations as Prestart-hooks, but depending on what these hooks do, possibly one of the other hooks could be used instead (such as CreateContainer or StartContainer). As these hooks are still supported, this patch adds nolint comments, but adds some TODOs to consider migrating to something else; daemon/nvidia_linux.go:86:2: SA1019: s.Hooks.Prestart is deprecated: use [Hooks.CreateRuntime], [Hooks.CreateContainer], and [Hooks.StartContainer] instead, which allow more granular hook control during the create and start phase. (staticcheck) s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ ^ daemon/oci_linux.go:76:5: SA1019: s.Hooks.Prestart is deprecated: use [Hooks.CreateRuntime], [Hooks.CreateContainer], and [Hooks.StartContainer] instead, which allow more granular hook control during the create and start phase. (staticcheck) s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
75 lines
2 KiB
Go
75 lines
2 KiB
Go
package daemon // import "github.com/docker/docker/daemon"
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
)
|
|
|
|
func toContainerdResources(resources container.Resources) *libcontainerdtypes.Resources {
|
|
var r libcontainerdtypes.Resources
|
|
|
|
if resources.BlkioWeight != 0 {
|
|
r.BlockIO = &specs.LinuxBlockIO{
|
|
Weight: &resources.BlkioWeight,
|
|
}
|
|
}
|
|
|
|
cpu := specs.LinuxCPU{
|
|
Cpus: resources.CpusetCpus,
|
|
Mems: resources.CpusetMems,
|
|
}
|
|
if resources.CPUShares != 0 {
|
|
shares := uint64(resources.CPUShares)
|
|
cpu.Shares = &shares
|
|
}
|
|
|
|
var (
|
|
period uint64
|
|
quota int64
|
|
)
|
|
if resources.NanoCPUs != 0 {
|
|
period = uint64(100 * time.Millisecond / time.Microsecond)
|
|
quota = resources.NanoCPUs * int64(period) / 1e9
|
|
}
|
|
if quota == 0 && resources.CPUQuota != 0 {
|
|
quota = resources.CPUQuota
|
|
}
|
|
if period == 0 && resources.CPUPeriod != 0 {
|
|
period = uint64(resources.CPUPeriod)
|
|
}
|
|
|
|
if period != 0 {
|
|
cpu.Period = &period
|
|
}
|
|
if quota != 0 {
|
|
cpu.Quota = "a
|
|
}
|
|
|
|
if cpu != (specs.LinuxCPU{}) {
|
|
r.CPU = &cpu
|
|
}
|
|
|
|
var memory specs.LinuxMemory
|
|
if resources.Memory != 0 {
|
|
memory.Limit = &resources.Memory
|
|
}
|
|
if resources.MemoryReservation != 0 {
|
|
memory.Reservation = &resources.MemoryReservation
|
|
}
|
|
if resources.KernelMemory != 0 { //nolint:staticcheck // ignore SA1019: memory.Kernel is deprecated: kernel-memory limits are not supported in cgroups v2, and were obsoleted in [kernel v5.4]. This field should no longer be used, as it may be ignored by runtimes.
|
|
memory.Kernel = &resources.KernelMemory //nolint:staticcheck // ignore SA1019: memory.Kernel is deprecated: kernel-memory limits are not supported in cgroups v2, and were obsoleted in [kernel v5.4]. This field should no longer be used, as it may be ignored by runtimes.
|
|
}
|
|
if resources.MemorySwap > 0 {
|
|
memory.Swap = &resources.MemorySwap
|
|
}
|
|
|
|
if memory != (specs.LinuxMemory{}) {
|
|
r.Memory = &memory
|
|
}
|
|
|
|
r.Pids = getPidsLimit(resources)
|
|
return &r
|
|
}
|