Skip to content

Commit 68aac13

Browse files
committed
chore: add CapAdd option
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 92e9a2d commit 68aac13

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

api/handlers/container/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
119119
capAdd = req.HostConfig.CapAdd
120120
}
121121

122+
capDrop := []string{}
123+
if req.HostConfig.CapDrop != nil {
124+
capDrop = req.HostConfig.CapDrop
125+
}
126+
122127
CpuQuota := int64(-1)
123128
if req.HostConfig.CPUQuota != 0 {
124129
CpuQuota = req.HostConfig.CPUQuota
@@ -194,7 +199,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
194199
// #region for security flags
195200
SecurityOpt: []string{}, // nerdctl default.
196201
CapAdd: capAdd,
197-
CapDrop: []string{}, // nerdctl default.
202+
CapDrop: capDrop,
198203
// #endregion
199204

200205
// #region for runtime flags

api/handlers/container/create_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,27 @@ var _ = Describe("Container Create API ", func() {
583583
Expect(rr.Body).Should(MatchJSON(jsonResponse))
584584
})
585585

586+
It("should set CapDrop option", func() {
587+
body := []byte(`{
588+
"Image": "test-image",
589+
"HostConfig": {
590+
"CapDrop": ["MKNOD"]
591+
}
592+
}`)
593+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
594+
595+
// expected create options
596+
createOpt.CapDrop = []string{"MKNOD"}
597+
598+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
599+
cid, nil)
600+
601+
// handler should return success message with 201 status code.
602+
h.create(rr, req)
603+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
604+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
605+
})
606+
586607
It("should return 404 if the image was not found", func() {
587608
body := []byte(`{"Image": "test-image"}`)
588609
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))

api/types/container_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type ContainerHostConfig struct {
7070
// TODO: Annotations map[string]string `json:",omitempty"` // Arbitrary non-identifying metadata attached to container and provided to the runtime
7171

7272
// Applicable to UNIX platforms
73-
CapAdd []string // List of kernel capabilities to add to the container
74-
// TODO: CapDrop strslice.StrSlice // List of kernel capabilities to remove from the container
73+
CapAdd []string // List of kernel capabilities to add to the container
74+
CapDrop []string // List of kernel capabilities to remove from the container
7575
// TODO: CgroupnsMode CgroupnsMode // Cgroup namespace mode to use for the container
7676
DNS []string `json:"Dns"` // List of DNS server to lookup
7777
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for

0 commit comments

Comments
 (0)