Skip to content

Commit fbbc0de

Browse files
authored
Merge pull request docker#10145 from ndeloof/ps_filter
don't filter by services if no filter was set
2 parents f1313f3 + b326a9d commit fbbc0de

File tree

2 files changed

+4
-18
lines changed

2 files changed

+4
-18
lines changed

pkg/compose/ps.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,9 @@ func (s *composeService) Ps(ctx context.Context, projectName string, options api
3737
return nil, err
3838
}
3939

40-
project := options.Project
41-
if project == nil {
42-
project, err = s.getProjectWithResources(ctx, containers, projectName)
43-
if err != nil {
44-
return nil, err
45-
}
40+
if len(options.Services) != 0 {
41+
containers = containers.filter(isService(options.Services...))
4642
}
47-
48-
if len(options.Services) == 0 {
49-
options.Services = project.ServiceNames()
50-
}
51-
52-
containers = containers.filter(isService(options.Services...))
5343
summary := make([]api.ContainerSummary, len(containers))
5444
eg, ctx := errgroup.WithContext(ctx)
5545
for i, container := range containers {

pkg/compose/ps_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ import (
2424
"github.com/golang/mock/gomock"
2525
"gotest.tools/v3/assert"
2626

27-
moby "github.com/docker/docker/api/types"
28-
"github.com/docker/docker/api/types/filters"
29-
"github.com/docker/docker/api/types/volume"
30-
3127
compose "github.com/docker/compose/v2/pkg/api"
3228
"github.com/docker/compose/v2/pkg/mocks"
29+
moby "github.com/docker/docker/api/types"
30+
"github.com/docker/docker/api/types/filters"
3331
)
3432

3533
func TestPs(t *testing.T) {
@@ -51,8 +49,6 @@ func TestPs(t *testing.T) {
5149
c2, inspect2 := containerDetails("service1", "456", "running", "", 0)
5250
c2.Ports = []moby.Port{{PublicPort: 80, PrivatePort: 90, IP: "localhost"}}
5351
c3, inspect3 := containerDetails("service2", "789", "exited", "", 130)
54-
api.EXPECT().VolumeList(ctx, gomock.Any()).Return(volume.ListResponse{}, nil)
55-
api.EXPECT().NetworkList(ctx, gomock.Any()).Return([]moby.NetworkResource{}, nil)
5652
api.EXPECT().ContainerList(ctx, listOpts).Return([]moby.Container{c1, c2, c3}, nil)
5753
api.EXPECT().ContainerInspect(anyCancellableContext(), "123").Return(inspect1, nil)
5854
api.EXPECT().ContainerInspect(anyCancellableContext(), "456").Return(inspect2, nil)

0 commit comments

Comments
 (0)