Skip to content

Commit f441247

Browse files
committed
add label_domain
1 parent c90644b commit f441247

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

podman_compose.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ def __init__(self):
16761676
self.commands = {}
16771677
self.global_args = None
16781678
self.project_name = None
1679+
self.label_domain = None
16791680
self.dirname = None
16801681
self.pods = None
16811682
self.containers = None
@@ -1793,6 +1794,7 @@ def _parse_compose_file(self):
17931794
relative_files = files
17941795
filename = files[0]
17951796
project_name = args.project_name
1797+
label_domain = args.label_domain
17961798
# no_ansi = args.no_ansi
17971799
# no_cleanup = args.no_cleanup
17981800
# dry_run = args.dry_run
@@ -1894,6 +1896,7 @@ def _parse_compose_file(self):
18941896
raise RuntimeError(f"Project name [{dir_basename}] normalized to empty")
18951897

18961898
self.project_name = project_name
1899+
self.label_domain = label_domain
18971900
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})
18981901

18991902
services = compose.get("services", None)
@@ -1938,18 +1941,15 @@ def _parse_compose_file(self):
19381941
raise RuntimeError(f"missing networks: {missing_nets_str}")
19391942
# volumes: [...]
19401943
self.vols = compose.get("volumes", {})
1941-
podman_compose_labels = list(set([
1942-
compose.label_domain + ".config-hash=" + self.yaml_hash,
1943-
compose.label_domain + ".project=" + project_name,
1944-
compose.label_domain + ".version=" + __version__,
1945-
"io.podman.compose.config-hash=" + self.yaml_hash,
1946-
"io.podman.compose.project=" + project_name,
1947-
"io.podman.compose.version=" + __version__,
1944+
podman_compose_labels = [
1945+
label_domain + ".config-hash=" + self.yaml_hash,
1946+
label_domain + ".project=" + project_name,
1947+
label_domain + ".version=" + __version__,
19481948
f"PODMAN_SYSTEMD_UNIT=podman-compose@{project_name}.service",
19491949
"com.docker.compose.project=" + project_name,
19501950
"com.docker.compose.project.working_dir=" + dirname,
19511951
"com.docker.compose.project.config_files=" + ",".join(relative_files),
1952-
]))
1952+
]
19531953
# other top-levels:
19541954
# networks: {driver: ...}
19551955
# configs: {...}
@@ -2119,6 +2119,13 @@ def _init_global_parser(parser):
21192119
type=str,
21202120
default=None,
21212121
)
2122+
parser.add_argument(
2123+
"--label-domain",
2124+
help="Specify an alternate root domain for resource labels (default: io.podman)",
2125+
type=str,
2126+
metavar="label_domain",
2127+
default="io.podman",
2128+
)
21222129
parser.add_argument(
21232130
"--podman-path",
21242131
help="Specify an alternate path to podman (default: use location in $PATH variable)",
@@ -2505,7 +2512,7 @@ async def compose_up(compose: PodmanCompose, args):
25052512
f"label={compose.label_domain}.project={compose.project_name}",
25062513
"-a",
25072514
"--format",
2508-
'{{ index .Labels "'+ compose.label_domain '.config-hash"}}',
2515+
'{{ index .Labels "' + compose.label_domain + '.config-hash"}}',
25092516
],
25102517
)
25112518
)

tests/unit/test_get_network_create_args.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ def test_minimal(self):
2626
args = get_network_create_args(net_desc, proj_name, net_name)
2727
self.assertEqual(args, expected_args)
2828

29+
def test_minimal_namespace(self):
30+
net_desc = {
31+
"labels": [],
32+
"internal": False,
33+
"driver": None,
34+
"driver_opts": {},
35+
"ipam": {"config": []},
36+
"enable_ipv6": False,
37+
}
38+
proj_name = "test_project"
39+
label_domain = "foo.bar",
40+
net_name = "test_network"
41+
expected_args = [
42+
"create",
43+
"--label",
44+
f"foo.bar.compose.project={proj_name}",
45+
"--label",
46+
f"com.docker.compose.project={proj_name}",
47+
net_name,
48+
]
49+
args = get_network_create_args(net_desc, proj_name, net_name, label_domain)
50+
self.assertEqual(args, expected_args)
51+
2952
def test_ipv6(self):
3053
net_desc = {
3154
"labels": [],

0 commit comments

Comments
 (0)