Skip to content

Commit 2fa691c

Browse files
committed
chore: add PidMode and Priviledged option
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent dad462f commit 2fa691c

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

api/handlers/container/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
172172
OomKillDisable: req.HostConfig.OomKillDisable,
173173
CidFile: req.HostConfig.ContainerIDFile, // CidFile write the container ID to the file
174174
OomScoreAdj: req.HostConfig.OomScoreAdj,
175+
Pid: req.HostConfig.PidMode, // Pid namespace to use
175176
// #endregion
176177

177178
// #region for platform flags
@@ -207,6 +208,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
207208
SecurityOpt: []string{}, // nerdctl default.
208209
CapAdd: capAdd,
209210
CapDrop: capDrop,
211+
Privileged: req.HostConfig.Privileged,
210212
// #endregion
211213

212214
// #region for runtime flags

api/handlers/container/create_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,29 @@ var _ = Describe("Container Create API ", func() {
629629
Expect(rr.Body).Should(MatchJSON(jsonResponse))
630630
})
631631

632+
It("should set PidMode and Privileged option", func() {
633+
body := []byte(`{
634+
"Image": "test-image",
635+
"HostConfig": {
636+
"PidMode": "host",
637+
"Privileged": true
638+
}
639+
}`)
640+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
641+
642+
// expected create options
643+
createOpt.Pid = "host"
644+
createOpt.Privileged = true
645+
646+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
647+
cid, nil)
648+
649+
// handler should return success message with 201 status code.
650+
h.create(rr, req)
651+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
652+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
653+
})
654+
632655
It("should return 404 if the image was not found", func() {
633656
body := []byte(`{"Image": "test-image"}`)
634657
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
@@ -825,6 +848,7 @@ func getDefaultCreateOpt(conf config.Config) types.ContainerCreateOptions {
825848
SecurityOpt: []string{}, // nerdctl default.
826849
CapAdd: []string{}, // nerdctl default.
827850
CapDrop: []string{}, // nerdctl default.
851+
Privileged: false,
828852
// #endregion
829853

830854
// #region for runtime flags

api/types/container_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ type ContainerHostConfig struct {
8181
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-
OomScoreAdj int // specifies the tune container’s OOM preferences (-1000 to 1000, rootless: 100 to 1000)
86-
// TODO: PidMode PidMode // PID namespace to use for the container
87-
// TODO: Privileged bool // Is the container in privileged mode
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)
86+
PidMode string // PID namespace to use for the container
87+
Privileged bool // Is the container in privileged mode
8888
// TODO: PublishAllPorts bool // Should docker publish all exposed port for the container
8989
// TODO: ReadonlyRootfs bool // Is the container root filesystem in read-only
9090
// TODO: SecurityOpt []string // List of string values to customize labels for MLS systems, such as SELinux.

0 commit comments

Comments
 (0)