From cf7319fc6e7f40d1717fd6892985181a9d12bfaa Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Thu, 9 Dec 2021 16:18:30 +0100 Subject: [PATCH] Only kill running containers Signed-off-by: Ulysses Souza --- cmd/compatibility/convert.go | 1 + pkg/compose/kill.go | 2 +- pkg/compose/kill_test.go | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/compatibility/convert.go b/cmd/compatibility/convert.go index 3ba162157..27a57063b 100644 --- a/cmd/compatibility/convert.go +++ b/cmd/compatibility/convert.go @@ -43,6 +43,7 @@ func getStringFlags() []string { } } +// Convert transforms standalone docker-compose args into CLI plugin compliant ones func Convert(args []string) []string { var rootFlags []string command := []string{compose.PluginName} diff --git a/pkg/compose/kill.go b/pkg/compose/kill.go index fb8199993..9bef116d0 100644 --- a/pkg/compose/kill.go +++ b/pkg/compose/kill.go @@ -42,7 +42,7 @@ func (s *composeService) kill(ctx context.Context, project *types.Project, optio } var containers Containers - containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...) + containers, err := s.getContainers(ctx, project.Name, oneOffInclude, false, services...) if err != nil { return err } diff --git a/pkg/compose/kill_test.go b/pkg/compose/kill_test.go index 6a85c31c2..91cc71844 100644 --- a/pkg/compose/kill_test.go +++ b/pkg/compose/kill_test.go @@ -45,7 +45,9 @@ func TestKillAll(t *testing.T) { project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService("service1"), testService("service2")}} ctx := context.Background() - api.EXPECT().ContainerList(ctx, projectFilterListOpt()).Return( + api.EXPECT().ContainerList(ctx, moby.ContainerListOptions{ + Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject))), + }).Return( []moby.Container{testContainer("service1", "123", false), testContainer("service1", "456", false), testContainer("service2", "789", false)}, nil) api.EXPECT().ContainerKill(anyCancellableContext(), "123", "").Return(nil) api.EXPECT().ContainerKill(anyCancellableContext(), "456", "").Return(nil) @@ -64,9 +66,7 @@ func TestKillSignal(t *testing.T) { project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{testService(serviceName)}} listOptions := moby.ContainerListOptions{ - Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)), - serviceFilter(serviceName)), - All: true, + Filters: filters.NewArgs(projectFilter(strings.ToLower(testProject)), serviceFilter(serviceName)), } ctx := context.Background()