mirror of
https://github.com/containers/podman.git
synced 2026-03-13 08:01:19 +08:00
compat/api: honor VolumeOptions.Subpath for HostConfig.Mounts
fixes: #27171 Signed-off-by: Jonathan Caicedo <jonathan@jcaicedo.com>
This commit is contained in:
@@ -255,6 +255,9 @@ func cliOpts(cc handlers.CreateContainerConfig, rtc *config.Config) (*entities.C
|
||||
addField(&builder, "tmpfs-mode", strconv.FormatUint(uint64(m.TmpfsOptions.Mode), 8))
|
||||
}
|
||||
case mount.TypeVolume:
|
||||
if m.VolumeOptions != nil {
|
||||
addField(&builder, "subpath", m.VolumeOptions.Subpath)
|
||||
}
|
||||
// All current VolumeOpts are handled above
|
||||
// See vendor/github.com/containers/common/pkg/parse/parse.go:ValidateVolumeOpts()
|
||||
}
|
||||
|
||||
@@ -37,3 +37,24 @@ t POST libpod/containers/create \
|
||||
500 \
|
||||
.cause="invalid mount option" \
|
||||
.message~"the 'noatime' option is only allowed with tmpfs mounts"
|
||||
|
||||
# Compat API: HostConfig.Mounts.VolumeOptions.Subpath mounts only the selected volume subdirectory
|
||||
subpath_vol="apiv2-subpath-vol"
|
||||
podman volume create "$subpath_vol"
|
||||
podman run --rm -v "$subpath_vol":/mnt "$IMAGE" sh -c "mkdir -p /mnt/test1 /mnt/test2; touch /mnt/test1/hello1; touch /mnt/test2/hello2"
|
||||
|
||||
t POST containers/create?name=compat_mount_subpath_test \
|
||||
Image=$IMAGE \
|
||||
Cmd='["ls","-1","/test1"]' \
|
||||
HostConfig='{"Mounts":[{"Type":"volume","Source":"'$subpath_vol'","Target":"/test1","VolumeOptions":{"Subpath":"test1"}}]}' \
|
||||
201 \
|
||||
.Id~[0-9a-f]\\{64\\}
|
||||
cid=$(jq -r '.Id' <<<"$output")
|
||||
|
||||
t POST containers/${cid}/start 204
|
||||
t POST containers/${cid}/wait 200
|
||||
t GET containers/${cid}/logs?stdout=true 200
|
||||
like "$(tr -d \\0 <$WORKDIR/curl.result.out)" ".*hello1$" "compat mount subpath returns only selected subdir"
|
||||
|
||||
t DELETE containers/${cid}?v=true 204
|
||||
podman volume rm "$subpath_vol"
|
||||
|
||||
Reference in New Issue
Block a user