Skip to content

Commit

Permalink
chore: add OomScoreAdjChanged
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Raja Yogidas <arjunry@amazon.com>
  • Loading branch information
coderbirju committed Jan 27, 2025
1 parent 5956e50 commit bc7a9bd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
30 changes: 18 additions & 12 deletions api/handlers/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,31 @@ 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,
Stderr: nil,
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
Expand Down
1 change: 1 addition & 0 deletions api/handlers/container/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 12 additions & 11 deletions api/types/container_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc7a9bd

Please sign in to comment.