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

fix: Add filter all=true to volume prune #77

Merged
merged 1 commit into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,14 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele
})

_ = try.Do(func(attempt int) (bool, error) {
volumesPruneReport, err := cli.VolumesPrune(context.Background(), args)
argsClone := args.Clone()

// API version >= v1.42 prunes only anonymous volumes: https://github.com/moby/moby/releases/tag/v23.0.0.
if serverVersion, err := cli.ServerVersion(context.Background()); err != nil && serverVersion.APIVersion >= "1.42" {
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
argsClone.Add("all", "true")
}

volumesPruneReport, err := cli.VolumesPrune(context.Background(), argsClone)
for _, volumeName := range volumesPruneReport.VolumesDeleted {
deletedVolumesMap[volumeName] = true
}
Expand All @@ -303,8 +310,9 @@ func prune(cli *client.Client, deathNote *sync.Map) (deletedContainers int, dele
})

_ = try.Do(func(attempt int) (bool, error) {
args.Add("dangling", "false")
imagesPruneReport, err := cli.ImagesPrune(context.Background(), args)
argsClone := args.Clone()
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
argsClone.Add("dangling", "false")
imagesPruneReport, err := cli.ImagesPrune(context.Background(), argsClone)
for _, image := range imagesPruneReport.ImagesDeleted {
if image.Untagged != "" {
deletedImagesMap[image.Untagged] = true
Expand Down
Loading