From f5209d23a8a9df3db6287a1e2c60638be1bf920c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 15 Apr 2024 15:53:55 +0200 Subject: [PATCH] daemon: add nolint-comments for deprecated kernel-memory options, hooks 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 --- daemon/daemon_unix.go | 4 ++-- daemon/nvidia_linux.go | 8 +++++++- daemon/oci_linux.go | 2 +- daemon/update_linux.go | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 120f514ef7..cda787b570 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -104,8 +104,8 @@ func getMemoryResources(config containertypes.Resources) *specs.LinuxMemory { memory.DisableOOMKiller = config.OomKillDisable } - if config.KernelMemory != 0 { - memory.Kernel = &config.KernelMemory + if config.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 = &config.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 config.KernelMemoryTCP != 0 { diff --git a/daemon/nvidia_linux.go b/daemon/nvidia_linux.go index 9f1c914146..7243b522bc 100644 --- a/daemon/nvidia_linux.go +++ b/daemon/nvidia_linux.go @@ -83,7 +83,13 @@ func setNvidiaGPUs(s *specs.Spec, dev *deviceInstance) error { if s.Hooks == nil { s.Hooks = &specs.Hooks{} } - s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ + + // This implementation uses prestart hooks, which are deprecated. + // CreateRuntime is 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). + s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ //nolint:staticcheck // FIXME(thaJeztah); replace prestart hook with a non-deprecated one. Path: path, Args: []string{ nvidiaHook, diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 37ad941847..75aecfa45f 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -73,7 +73,7 @@ func withLibnetwork(daemon *Daemon, daemonCfg *dconfig.Config, c *container.Cont s.Hooks = &specs.Hooks{} } shortNetCtlrID := stringid.TruncateID(daemon.netController.ID()) - s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ + s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{ //nolint:staticcheck // FIXME(thaJeztah); replace prestart hook with a non-deprecated one. Path: filepath.Join("/proc", strconv.Itoa(os.Getpid()), "exe"), Args: []string{"libnetwork-setkey", "-exec-root=" + daemonCfg.GetExecRoot(), c.ID, shortNetCtlrID}, }) diff --git a/daemon/update_linux.go b/daemon/update_linux.go index 3105402e3c..8f3bde9eed 100644 --- a/daemon/update_linux.go +++ b/daemon/update_linux.go @@ -59,8 +59,8 @@ func toContainerdResources(resources container.Resources) *libcontainerdtypes.Re if resources.MemoryReservation != 0 { memory.Reservation = &resources.MemoryReservation } - if resources.KernelMemory != 0 { - memory.Kernel = &resources.KernelMemory + 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