Skip to content

Commit 44499e3

Browse files
committed
chore: add VolumesFrom option
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent f1e67fa commit 44499e3

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

api/handlers/container/create.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
139139
memorySwappiness = req.HostConfig.MemorySwappiness
140140
}
141141

142+
volumesFrom := []string{}
143+
if req.HostConfig.VolumesFrom != nil {
144+
volumesFrom = req.HostConfig.VolumesFrom
145+
}
146+
142147
globalOpt := ncTypes.GlobalCommandOptions(*h.Config)
143148
createOpt := ncTypes.ContainerCreateOptions{
144149
Stdout: nil,
@@ -197,7 +202,8 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
197202
// #endregion
198203

199204
// #region for volume flags
200-
Volume: volumes,
205+
Volume: volumes,
206+
VolumesFrom: volumesFrom,
201207
// #endregion
202208

203209
// #region for env flags

api/handlers/container/create_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,27 @@ var _ = Describe("Container Create API ", func() {
562562
Expect(rr.Body).Should(MatchJSON(jsonResponse))
563563
})
564564

565+
It("should set VolumesFrom option", func() {
566+
body := []byte(`{
567+
"Image": "test-image",
568+
"HostConfig": {
569+
"VolumesFrom": [ "parent", "other:ro"]
570+
}
571+
}`)
572+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
573+
574+
// expected create options
575+
createOpt.VolumesFrom = []string{"parent", "other:ro"}
576+
577+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
578+
cid, nil)
579+
580+
// handler should return success message with 201 status code.
581+
h.create(rr, req)
582+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
583+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
584+
})
585+
565586
It("should return 404 if the image was not found", func() {
566587
body := []byte(`{"Image": "test-image"}`)
567588
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
@@ -765,7 +786,8 @@ func getDefaultCreateOpt(conf config.Config) types.ContainerCreateOptions {
765786
// #endregion
766787

767788
// #region for volume flags
768-
Volume: nil,
789+
Volume: nil,
790+
VolumesFrom: []string{}, // nerdctl default.
769791
// #endregion
770792

771793
// #region for env flags

api/types/container_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ type ContainerHostConfig struct {
6464
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
6565
RestartPolicy RestartPolicy // Restart policy to be used for the container
6666
AutoRemove bool // Automatically remove container when it exits
67+
VolumesFrom []string // List of volumes to take from other container
6768
// TODO: VolumeDriver string // Name of the volume driver used to mount volumes
68-
// TODO: VolumesFrom []string // List of volumes to take from other container
6969
// TODO: ConsoleSize [2]uint // Initial console size (height,width)
7070
// TODO: Annotations map[string]string `json:",omitempty"` // Arbitrary non-identifying metadata attached to container and provided to the runtime
7171

0 commit comments

Comments
 (0)