Skip to content

Commit dad462f

Browse files
committed
chore: add IPC and OomScoreAdj option
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent b08a423 commit dad462f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

api/handlers/container/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
171171
StopTimeout: stopTimeout,
172172
OomKillDisable: req.HostConfig.OomKillDisable,
173173
CidFile: req.HostConfig.ContainerIDFile, // CidFile write the container ID to the file
174+
OomScoreAdj: req.HostConfig.OomScoreAdj,
174175
// #endregion
175176

176177
// #region for platform flags
@@ -194,6 +195,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
194195
CPUSetMems: req.HostConfig.CPUSetMems, // CpusetMems 0-2, 0,1
195196
MemoryReservation: memoryReservation, // Memory soft limit (in bytes)
196197
MemorySwap: memorySwap, // Total memory usage (memory + swap); set `-1` to enable unlimited swap
198+
IPC: req.HostConfig.IpcMode, // IPC namespace to use
197199
// #endregion
198200

199201
// #region for user flags

api/handlers/container/create_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,29 @@ var _ = Describe("Container Create API ", func() {
606606
Expect(rr.Body).Should(MatchJSON(jsonResponse))
607607
})
608608

609+
It("should set IPC and OomScoreAdj option", func() {
610+
body := []byte(`{
611+
"Image": "test-image",
612+
"HostConfig": {
613+
"IpcMode": "host",
614+
"OomScoreAdj": 200
615+
}
616+
}`)
617+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
618+
619+
// expected create options
620+
createOpt.IPC = "host"
621+
createOpt.OomScoreAdj = 200
622+
623+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
624+
cid, nil)
625+
626+
// handler should return success message with 201 status code.
627+
h.create(rr, req)
628+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
629+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
630+
})
631+
609632
It("should return 404 if the image was not found", func() {
610633
body := []byte(`{"Image": "test-image"}`)
611634
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))

api/types/container_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ type ContainerHostConfig struct {
7878
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
7979
ExtraHosts []string // List of extra hosts
8080
GroupAdd []string // List of additional groups that the container process will run as
81-
// TODO: IpcMode IpcMode // IPC namespace to use for the container
81+
IpcMode string // IPC namespace to use for the container
8282
// TODO: Cgroup CgroupSpec // Cgroup to use for the container
8383
// TODO: Links []string // List of links (in the name:alias form)
84-
OomKillDisable bool //specifies whether to disable OOM Killer
85-
// TODO: OomScoreAdj int // Container preference for OOM-killing
84+
OomKillDisable bool // specifies whether to disable OOM Killer
85+
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
8686
// TODO: PidMode PidMode // PID namespace to use for the container
8787
// TODO: Privileged bool // Is the container in privileged mode
8888
// TODO: PublishAllPorts bool // Should docker publish all exposed port for the container

0 commit comments

Comments
 (0)