-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates handling of scale/replicas parameter in CLI and compose file #1159
base: main
Are you sure you want to change the base?
Conversation
d007b86
to
4a21e9c
Compare
podman_compose.py
Outdated
@@ -2080,7 +2080,17 @@ def _parse_compose_file(self): | |||
container_names_by_service = {} | |||
self.services = services | |||
for service_name, service_desc in services.items(): | |||
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1) | |||
replicas = try_int(args.scale, fallback=1) if "scale" in args else 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use None
to signify that no value has been supplied, and then handle the None case at the very end. Right now if explicit 1 value is passed it may be overridden by next steps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @p12tic for the review and suggestion.
I've updated the code to handle the cases:
--scale
from the CLIup
commandscale
from compose yaml file{"deploy": {"replicas": <NUM>}
from compose yaml file
Was tempted to use the new fancy match-cases, but didn't to maintain compatibility with pre-Python-2.10 versions.
Do let me know if the new code is fine.
Also, I've modified the compose_down
function to behave more closely to the docker compose down
command:
8036f67
a17250b
to
0ed56ed
Compare
podman_compose.py
Outdated
) | ||
) | ||
await asyncio.gather(*down_tasks) | ||
await compose.podman.run([], "stop", [*podman_stop_args, cnt["name"]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will way on all services to stop one by one. This is problematic in case of large number of services. One deployment I have is 40 services for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They would stop in parallel as await yields from the compose.podman.run([], "stop", [*podman_stop_args, cnt["name"]])
.
So rather than waiting for asyncio.gather
to schedule the future tasks/co-routines, here they get scheduled as soon as they are passed and the control returns.
However, the concern is valid. It won't wait for all the stop tasks to finish before proceeding to await compose.podman.run([], "rm", [cnt["name"]])
. I'll try to fix it. (Ideally should be upgraded to TaskGroup, but for that there has to be an upgrade mandate to Python 3.11 for compatibility reasons).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Updated the code to use asyncio.gather
for stop
and rm
command tasks.
No need to add |
Signed-off-by: Yashodhan Pise <[email protected]>
Signed-off-by: Yashodhan Pise <[email protected]>
c82c1c3
to
43d93cd
Compare
Signed-off-by: Yashodhan Pise <[email protected]>
43d93cd
to
b2f1b87
Compare
Overall code looks good. We need integration tests. You've already done most of the work and provided compose file and expected output in the PR description. What's left is to automate it. Check out tests/integration for examples of how this can be done. Updates to compose_down command to match docker compose behavior should probably live in another PR because the change is unrelated. This would make it easier to land "Updates handling of scale/replicas through CLI & compose file" commit. Talking about Updates to compose_down command to match docker compose behavior, it also needs tests and release note (probably several, because more than one thing is fixed). Also, I would say that the commit should itself be split into several, because right now it's hard to understand what the commit is trying to achieve. It's clear that it does improve something, but it contains several improvements merged into one. |
Purpose
Addresses issue: #267
Contributor Checklist:
This PR attempts to address missing (the code to accommodate this was already present, just broken)
--scale
option forpodman-compose up
:https://docs.docker.com/reference/cli/docker/compose/up/#options
All changes require additional unit tests.
Testing
Test file:
With compose file:
Scale existing services using CLI:
To-Do
=> That part of code yet needs to be addressed, may be through a separate issue.
down
(to destroy the scaled containers/replicas) works only based on value assigned in compose yaml file. This instead, needs to be addressed to stop all running replicas.=> Done