Skip to content

Commit b4728f4

Browse files
committed
fix(volumes): manage subpath into volume
Force refer_volume_over_mount to false and add code to add subpath option in podman command line. Signed-off-by: fccagou <[email protected]>
1 parent a1f3bef commit b4728f4

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

podman_compose.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ def mount_desc_to_mount_args(mount_desc: dict[str, Any]) -> str:
480480
selinux = bind_opts.get("selinux")
481481
if selinux is not None:
482482
opts.append(selinux)
483+
else:
484+
subpath = mount_desc.get("subpath")
485+
if subpath is not None:
486+
opts.append(f"subpath={subpath}")
483487
opts_str = ",".join(opts)
484488
if mount_type == "bind":
485489
return f"type=bind,source={source},destination={target},{opts_str}".rstrip(",")
@@ -1186,7 +1190,6 @@ async def container_to_args(
11861190
podman_args.extend(["--tmpfs", i])
11871191
for volume in cnt.get("volumes", []):
11881192
podman_args.extend(await get_mount_args(compose, cnt, volume))
1189-
11901193
await assert_cnt_nets(compose, cnt)
11911194
podman_args.extend(get_net_args(compose, cnt))
11921195

@@ -2064,7 +2067,7 @@ def __init__(self) -> None:
20642067
self.container_by_name: dict[str, Any]
20652068
self.services: dict[str, Any]
20662069
self.all_services: set[Any] = set()
2067-
self.prefer_volume_over_mount = True
2070+
self.prefer_volume_over_mount = False
20682071
self.x_podman: dict[PodmanCompose.XPodmanSettingKey, Any] = {}
20692072
self.merged_yaml: Any
20702073
self.yaml_hash = ""

tests/integration/selinux/test_podman_compose_selinux.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def test_selinux(self) -> None:
3838
inspect_out = json.loads(out)
3939
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
4040
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
41-
self.assertIn(f'{host_path}:/test_text.txt:z', create_command_list)
41+
try:
42+
# podman-compose.py: prefer_volume_over_mount set to False
43+
self.assertIn(
44+
f'type=bind,source={host_path},destination=/test_text.txt,z',
45+
create_command_list,
46+
)
47+
except AssertionError:
48+
# podman-compose.py: prefer_volume_over_mount set to True
49+
self.assertIn(f'{host_path}:/test_text.txt:z', create_command_list)
4250

4351
out, _ = self.run_subprocess_assert_returncode([
4452
"podman",
@@ -48,7 +56,14 @@ def test_selinux(self) -> None:
4856
inspect_out = json.loads(out)
4957
create_command_list = inspect_out[0].get("Config", []).get("CreateCommand", [])
5058
host_path = os.path.join(test_path(), "selinux", "host_test_text.txt")
51-
self.assertIn(f'{host_path}:/test_text.txt', create_command_list)
59+
try:
60+
# podman-compose.py: prefer_volume_over_mount set to False
61+
self.assertIn(
62+
f'type=bind,source={host_path},destination=/test_text.txt', create_command_list
63+
)
64+
except AssertionError:
65+
# podman-compose.py: prefer_volume_over_mount set to True
66+
self.assertIn(f'{host_path}:/test_text.txt', create_command_list)
5267
finally:
5368
out, _ = self.run_subprocess_assert_returncode([
5469
podman_compose_path(),

0 commit comments

Comments
 (0)