Skip to content

Commit b08a423

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

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

api/handlers/container/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
149149
volumesFrom = req.HostConfig.VolumesFrom
150150
}
151151

152+
groupAdd := []string{}
153+
if req.HostConfig.GroupAdd != nil {
154+
groupAdd = req.HostConfig.GroupAdd
155+
}
156+
152157
globalOpt := ncTypes.GlobalCommandOptions(*h.Config)
153158
createOpt := ncTypes.ContainerCreateOptions{
154159
Stdout: nil,
@@ -193,7 +198,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
193198

194199
// #region for user flags
195200
User: req.User,
196-
GroupAdd: []string{}, // nerdctl default.
201+
GroupAdd: groupAdd,
197202
// #endregion
198203

199204
// #region for security flags

api/handlers/container/create_test.go

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

586-
It("should set CapDrop option", func() {
586+
It("should set CapDrop and GroupAdd option", func() {
587587
body := []byte(`{
588588
"Image": "test-image",
589589
"HostConfig": {
590-
"CapDrop": ["MKNOD"]
590+
"CapDrop": ["MKNOD"],
591+
"GroupAdd": ["someGroup"]
591592
}
592593
}`)
593594
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
594595

595596
// expected create options
596597
createOpt.CapDrop = []string{"MKNOD"}
598+
createOpt.GroupAdd = []string{"someGroup"}
597599

598600
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
599601
cid, nil)

api/types/container_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type ContainerHostConfig struct {
7777
DNSOptions []string `json:"DnsOptions"` // List of DNSOption to look for
7878
DNSSearch []string `json:"DnsSearch"` // List of DNSSearch to look for
7979
ExtraHosts []string // List of extra hosts
80-
// TODO: GroupAdd []string // List of additional groups that the container process will run as
80+
GroupAdd []string // List of additional groups that the container process will run as
8181
// TODO: IpcMode IpcMode // 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)

0 commit comments

Comments
 (0)