Skip to content

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

Merged
ndeloof merged 1 commit into
docker:mainfrom
1arp:main
Feb 9, 2024
Merged

ndeloof merged 1 commit into
docker:mainfrom
1arp:main

Conversation

@1arp

@1arp 1arp commented Feb 8, 2024

Copy link
Copy Markdown
Contributor

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

1arp commented Feb 8, 2024

Copy link
Copy Markdown
Contributor Author

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

1arp commented Feb 8, 2024 •

Copy link
Copy Markdown
Contributor Author

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

@ndeloof ndeloof left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread cmd/compose/ps.go Outdated
containers, err := backend.Ps(ctx, name, api.PsOptions{
Project: project,
All: opts.All,
All: opts.All || containsStatus(opts.Status, "exited"),

Copy link
Copy Markdown
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

@1arp 1arp Feb 8, 2024 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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>
@codecov

codecov Bot commented Feb 8, 2024

Copy link
Copy Markdown

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

1arp commented Feb 9, 2024 •

Copy link
Copy Markdown
Contributor Author

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

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