Skip to content
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

pass All option to backend api.Service when length statuses is not equal to zero #11475

Merged
merged 1 commit into from Feb 9, 2024

Conversation

1arp
Copy link
Contributor

@1arp 1arp commented Feb 8, 2024

What I did
For ps command: Aligned --status=exited behaviour with the documentation.
https://docs.docker.com/engine/reference/commandline/compose_ps/#status

The compose service internally calls docker cli client which lists only running containers by default unless the all flag is passed.

With the change the all flag is passed when the statuses includes exited.

Related issue

Fixes #11464

(not mandatory) A picture of a cute animal, if possible in relation to what you did
image

@1arp
Copy link
Contributor Author

1arp commented Feb 8, 2024

I am not sure if the issue is the code or the documentation. The PR addresses the issue in the code but the issue could also be the documentation. :)

@1arp
Copy link
Contributor Author

1arp commented Feb 8, 2024

@ndeloof would appreciate it if you could take a look here

Copy link
Contributor

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT, could be simplified by just forcing All when a status filter is selected

@@ -113,7 +113,7 @@ func runPs(ctx context.Context, dockerCli command.Cli, backend api.Service, serv

containers, err := backend.Ps(ctx, name, api.PsOptions{
Project: project,
All: opts.All,
All: opts.All || containsStatus(opts.Status, "exited"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT as long as we filter by status we can force All, as irrelevant containers will anyway be filtered

Copy link
Contributor Author

@1arp 1arp Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right but in cases where users explicitly set it to false we will not be able to see the exited containers.
IMO either we should throw an error in these cases or have the default behaviour as in the change.
Open to your opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opts.All || opts.Status != "" sounds enough to me. We could check --all flag was not intentionally set to false in command PreRun to prevent misuse, but as a corner case with no benefit I wouldn't worry about it

…ual to zero

Signed-off-by: 1arp <dekhijaegi@gmail.com>
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (6ef55a5) 58.09% compared to head (d720d22) 58.12%.
Report is 4 commits behind head on main.

Files Patch % Lines
pkg/compose/convergence.go 66.66% 4 Missing and 2 partials ⚠️
pkg/compose/create.go 89.28% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11475      +/-   ##
==========================================
+ Coverage   58.09%   58.12%   +0.03%     
==========================================
  Files         136      136              
  Lines       11543    11581      +38     
==========================================
+ Hits         6706     6732      +26     
- Misses       4177     4185       +8     
- Partials      660      664       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@1arp 1arp changed the title pass All option to backend api.Service when statuses include exited pass All option to backend api.Service when length statuses is not equal to zero Feb 8, 2024
@1arp
Copy link
Contributor Author

1arp commented Feb 9, 2024

@ndeloof Can you please rerun the tests, seems like there was a timeout while getting the docker image.

@ndeloof ndeloof merged commit 3ba6645 into docker:main Feb 9, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] docker compose ps --status behavior differs from documentation
2 participants