Updates handling of scale/replicas through CLI & compose file

Signed-off-by: Yashodhan Pise <technoy@gmail.com>
This commit is contained in:
Yashodhan Pise 2025-03-07 15:59:58 +05:30
parent 04fcc26a79
commit 2edd4f376c

View File

@ -2095,6 +2095,22 @@ class PodmanCompose:
container_names_by_service = {}
self.services = services
for service_name, service_desc in services.items():
replicas = 1
if "scale" in args and args.scale is not None:
# Check `--scale` args from CLI command
scale_args = args.scale.split('=')
if service_name == scale_args[0]:
replicas = try_int(scale_args[1], fallback=1)
elif "scale" in service_desc:
# Check `scale` value from compose yaml file
replicas = try_int(service_desc.get("scale"), fallback=1)
elif (
"deploy" in service_desc
and "replicas" in service_desc.get("deploy", {})
and "replicated" == service_desc.get("deploy", {}).get("mode", '')
):
# Check `deploy: replicas:` value from compose yaml file
# Note: All conditions are necessary to handle case
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1)
container_names_by_service[service_name] = []
@ -3383,12 +3399,13 @@ def compose_up_parse(parser):
action="store_true",
help="Remove containers for services not defined in the Compose file.",
)
# `--scale` argument needs to store as single value and not append,
# as multiple scale values could be confusing.
parser.add_argument(
"--scale",
metavar="SERVICE=NUM",
action="append",
help="Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
"present.",
help="Scale SERVICE to NUM instances. "
"Overrides the `scale` setting in the Compose file if present.",
)
parser.add_argument(
"--exit-code-from",