Skip to content

Commit fa242d8

Browse files
authored
fix(host-cleanup): don't prune containers #6762
1 parent fd9b2ca commit fa242d8

8 files changed

+2
-75
lines changed

Diff for: pkg/container_backend/buildah_backend.go

-4
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,6 @@ func (backend *BuildahBackend) PostManifest(ctx context.Context, ref string, opt
11011101

11021102
func (backend *BuildahBackend) ClaimTargetPlatforms(ctx context.Context, targetPlatforms []string) {}
11031103

1104-
func (backend *BuildahBackend) PruneContainers(_ context.Context, _ prune.Options) (prune.Report, error) {
1105-
return prune.Report{}, ErrUnsupportedFeature
1106-
}
1107-
11081104
func (backend *BuildahBackend) PruneImages(ctx context.Context, options prune.Options) (prune.Report, error) {
11091105
report, err := backend.buildah.PruneImages(ctx, buildah.PruneImagesOptions{})
11101106
if err != nil {

Diff for: pkg/container_backend/docker_server_backend.go

-8
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,6 @@ func (backend *DockerServerBackend) PostManifest(ctx context.Context, ref string
391391
return docker.CreateImage(ctx, ref, docker.CreateImageOptions{Labels: opts.Labels})
392392
}
393393

394-
func (backend *DockerServerBackend) PruneContainers(ctx context.Context, options prune.Options) (prune.Report, error) {
395-
report, err := docker.ContainersPrune(ctx, docker.ContainersPruneOptions(options))
396-
if err != nil {
397-
return prune.Report{}, fmt.Errorf("unable to prune docker containers: %w", err)
398-
}
399-
return prune.Report(report), nil
400-
}
401-
402394
func (backend *DockerServerBackend) PruneImages(ctx context.Context, options prune.Options) (prune.Report, error) {
403395
report, err := docker.ImagesPrune(ctx, docker.ImagesPruneOptions(options))
404396
if err != nil {

Diff for: pkg/container_backend/interface.go

-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ type ContainerBackend interface {
100100

101101
ClaimTargetPlatforms(ctx context.Context, targetPlatforms []string)
102102

103-
// PruneContainers removes all stopped containers
104-
PruneContainers(ctx context.Context, options prune.Options) (prune.Report, error)
105103
// PruneImages removes all dangling images
106104
PruneImages(ctx context.Context, options prune.Options) (prune.Report, error)
107105
// PruneVolumes removes all anonymous volumes not used by at least one container

Diff for: pkg/container_backend/perf_check_container_backend.go

-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,6 @@ func (runtime *PerfCheckContainerBackend) ClaimTargetPlatforms(ctx context.Conte
198198
Do(func() { runtime.ContainerBackend.ClaimTargetPlatforms(ctx, targetPlatforms) })
199199
}
200200

201-
func (runtime *PerfCheckContainerBackend) PruneContainers(ctx context.Context, options prune.Options) (report prune.Report, err error) {
202-
logboek.Context(ctx).Default().LogProcess("ContainerBackend.PruneContainers %v", options).
203-
Do(func() {
204-
report, err = runtime.ContainerBackend.PruneContainers(ctx, options)
205-
})
206-
return
207-
}
208-
209201
func (runtime *PerfCheckContainerBackend) PruneImages(ctx context.Context, options prune.Options) (report prune.Report, err error) {
210202
logboek.Context(ctx).Default().LogProcess("ContainerBackend.PruneImages %v", options).
211203
Do(func() {

Diff for: pkg/docker/container.go

-19
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import (
66
"github.com/docker/cli/cli/command"
77
"github.com/docker/cli/cli/command/container"
88
"github.com/docker/docker/api/types"
9-
"github.com/docker/docker/api/types/filters"
109
"github.com/docker/docker/client"
1110
"golang.org/x/net/context"
12-
13-
"github.com/werf/werf/v2/pkg/container_backend/prune"
1411
)
1512

1613
func Containers(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
@@ -48,22 +45,6 @@ func ContainerRemove(ctx context.Context, ref string, options types.ContainerRem
4845
return apiCli(ctx).ContainerRemove(ctx, ref, options)
4946
}
5047

51-
type (
52-
ContainersPruneOptions prune.Options
53-
ContainersPruneReport prune.Report
54-
)
55-
56-
func ContainersPrune(ctx context.Context, _ ContainersPruneOptions) (ContainersPruneReport, error) {
57-
report, err := apiCli(ctx).ContainersPrune(ctx, filters.NewArgs())
58-
if err != nil {
59-
return ContainersPruneReport{}, err
60-
}
61-
return ContainersPruneReport{
62-
ItemsDeleted: report.ContainersDeleted,
63-
SpaceReclaimed: report.SpaceReclaimed,
64-
}, nil
65-
}
66-
6748
func doCliCreate(c command.Cli, args ...string) error {
6849
return prepareCliCmd(container.NewCreateCommand(c), args...).Execute()
6950
}

Diff for: pkg/host_cleaning/local_backend_cleaner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
412412
return nil
413413
}
414414

415-
// Step 4. Remove werf containers
415+
// Step 3. Remove werf containers
416416
err = logboek.Context(ctx).LogBlock("Cleanup werf containers").DoError(func() error {
417417
reportWerfContainers, err := cleaner.safeCleanupWerfContainers(ctx, options, vu)
418418
if err != nil {
@@ -430,7 +430,7 @@ func (cleaner *LocalBackendCleaner) RunGC(ctx context.Context, options RunGCOpti
430430
return fmt.Errorf("unable to remove werf containers: %w", err)
431431
}
432432

433-
// Step 5. Remove werf images
433+
// Step 4. Remove werf images
434434
err = logboek.Context(ctx).LogBlock("Cleanup werf images").DoError(func() error {
435435
reportWerfImages, err := cleaner.safeCleanupWerfImages(ctx, options, vu, targetVolumeUsagePercentage)
436436
if err != nil {

Diff for: pkg/host_cleaning/local_backend_cleaner_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,6 @@ var _ = Describe("LocalBackendCleaner", func() {
9797
})
9898
})
9999

100-
Describe("pruneContainers", func() {
101-
It("should return err if opts.DryRun=true", func() {
102-
_, err := cleaner.pruneContainers(ctx, RunGCOptions{
103-
DryRun: true,
104-
})
105-
Expect(errors.Is(err, errOptionDryRunNotSupported)).To(BeTrue())
106-
})
107-
It("should call backend.PruneContainers() if opts.DryRun=true", func() {
108-
backend.EXPECT().PruneContainers(ctx, prune.Options{}).Return(prune.Report{}, nil)
109-
110-
report, err := cleaner.pruneContainers(ctx, RunGCOptions{})
111-
Expect(err).To(Succeed())
112-
Expect(report).To(Equal(newCleanupReport()))
113-
})
114-
})
115-
116100
Describe("pruneImages", func() {
117101
var filters filter.FilterList
118102
BeforeEach(func() {
@@ -380,7 +364,6 @@ var _ = Describe("LocalBackendCleaner", func() {
380364
// keep orders of backend calls
381365
gomock.InOrder(
382366
// use backend native GC pruning
383-
backend.EXPECT().PruneContainers(ctx, prune.Options{}).Return(prune.Report{}, nil),
384367
backend.EXPECT().PruneVolumes(ctx, prune.Options{}).Return(prune.Report{}, nil),
385368
backend.EXPECT().PruneImages(ctx, prune.Options{Filters: imagesFilters}).Return(prune.Report{}, nil),
386369

Diff for: test/mock/container_backend.go

-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)