From bc7a9bde7d3b9e3577a3f77517738312fc3b85ab Mon Sep 17 00:00:00 2001 From: Arjun Raja Yogidas Date: Mon, 27 Jan 2025 05:37:21 +0000 Subject: [PATCH] chore: add OomScoreAdjChanged Signed-off-by: Arjun Raja Yogidas --- api/handlers/container/create.go | 30 ++++++++++++++++----------- api/handlers/container/create_test.go | 1 + api/types/container_types.go | 23 ++++++++++---------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/api/handlers/container/create.go b/api/handlers/container/create.go index e6d08781..cadfdddc 100644 --- a/api/handlers/container/create.go +++ b/api/handlers/container/create.go @@ -238,6 +238,11 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) { cgroupnsMode = string(req.HostConfig.CgroupnsMode) } + var oomScoreAdjChanged bool + if req.HostConfig.OomScoreAdj != 0 || req.HostConfig.OomScoreAdjChanged { + oomScoreAdjChanged = req.HostConfig.OomScoreAdjChanged + } + globalOpt := ncTypes.GlobalCommandOptions(*h.Config) createOpt := ncTypes.ContainerCreateOptions{ Stdout: nil, @@ -245,18 +250,19 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) { GOptions: globalOpt, // #region for basic flags - Interactive: false, // TODO: update this after attach supports STDIN - TTY: false, // TODO: update this after attach supports STDIN - Detach: true, // TODO: current implementation of create does not support AttachStdin, AttachStdout, and AttachStderr flags - Restart: restart, // Restart policy to apply when a container exits. - Rm: req.HostConfig.AutoRemove, // Automatically remove container upon exit. - Pull: "missing", // nerdctl default. - StopSignal: stopSignal, - StopTimeout: stopTimeout, - CidFile: req.HostConfig.ContainerIDFile, // CidFile write the container ID to the file - OomKillDisable: req.HostConfig.OomKillDisable, - OomScoreAdj: req.HostConfig.OomScoreAdj, - Pid: req.HostConfig.PidMode, // Pid namespace to use + Interactive: false, // TODO: update this after attach supports STDIN + TTY: false, // TODO: update this after attach supports STDIN + Detach: true, // TODO: current implementation of create does not support AttachStdin, AttachStdout, and AttachStderr flags + Restart: restart, // Restart policy to apply when a container exits. + Rm: req.HostConfig.AutoRemove, // Automatically remove container upon exit. + Pull: "missing", // nerdctl default. + StopSignal: stopSignal, + StopTimeout: stopTimeout, + CidFile: req.HostConfig.ContainerIDFile, // CidFile write the container ID to the file + OomKillDisable: req.HostConfig.OomKillDisable, + OomScoreAdj: req.HostConfig.OomScoreAdj, + OomScoreAdjChanged: oomScoreAdjChanged, + Pid: req.HostConfig.PidMode, // Pid namespace to use // #endregion // #region for platform flags diff --git a/api/handlers/container/create_test.go b/api/handlers/container/create_test.go index 6192321e..4dcc9f9c 100644 --- a/api/handlers/container/create_test.go +++ b/api/handlers/container/create_test.go @@ -783,6 +783,7 @@ var _ = Describe("Container Create API ", func() { // expected create options createOpt.IPC = "host" createOpt.OomScoreAdj = 200 + createOpt.OomScoreAdjChanged = true service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return( cid, nil) diff --git a/api/types/container_types.go b/api/types/container_types.go index 2e0ffd83..b36aaec1 100644 --- a/api/types/container_types.go +++ b/api/types/container_types.go @@ -82,17 +82,18 @@ type ContainerHostConfig struct { IpcMode string // IPC namespace to use for the container // TODO: Cgroup CgroupSpec // Cgroup to use for the container // TODO: Links []string // List of links (in the name:alias form) - OomKillDisable bool // specifies whether to disable OOM Killer - OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000) - PidMode string // PID namespace to use for the container - Privileged bool // Is the container in privileged mode - ReadonlyRootfs bool // Is the container root filesystem in read-only - SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. (["key=value"]) - Tmpfs map[string]string `json:",omitempty"` // List of tmpfs (mounts) used for the container - UTSMode string // UTS namespace to use for the container - ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0. - Sysctls map[string]string `json:",omitempty"` // List of Namespaced sysctls used for the container - Runtime string `json:",omitempty"` // Runtime to use with this container + OomKillDisable bool // specifies whether to disable OOM Killer + OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000) + OomScoreAdjChanged bool // OomScoreAdjChanged specifies whether the OOM preferences has been changed + PidMode string // PID namespace to use for the container + Privileged bool // Is the container in privileged mode + ReadonlyRootfs bool // Is the container root filesystem in read-only + SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux. (["key=value"]) + Tmpfs map[string]string `json:",omitempty"` // List of tmpfs (mounts) used for the container + UTSMode string // UTS namespace to use for the container + ShmSize int64 // Size of /dev/shm in bytes. The size must be greater than 0. + Sysctls map[string]string `json:",omitempty"` // List of Namespaced sysctls used for the container + Runtime string `json:",omitempty"` // Runtime to use with this container // TODO: PublishAllPorts bool // Should docker publish all exposed port for the container // TODO: StorageOpt map[string]string `json:",omitempty"` // Storage driver options per container. // TODO: UsernsMode UsernsMode // The user namespace to use for the container