Merge pull request #28464 from simonbrauner/volume-prune-fix-all-filter

Fix inconsistencies between --all and --filter=all in volume prune
This commit is contained in:
Tom Sweeney
2026-04-10 17:03:31 -04:00
committed by GitHub
2 changed files with 19 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package volumes
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"strings"
@@ -64,6 +65,11 @@ func prune(cmd *cobra.Command, _ []string) error {
// --all adds filter all=true (Docker-compatible; behavior is filter-only)
allFlag, _ := cmd.Flags().GetBool("all")
filterAllFlag := strings.EqualFold(pruneOptions.Filters.Get("all"), "true")
if allFlag && filterAllFlag {
return errors.New("--all and --filter all cannot be used together")
}
allFlag = allFlag || filterAllFlag
if allFlag {
pruneOptions.Filters.Set("all", "true")
}
@@ -79,6 +85,7 @@ func prune(cmd *cobra.Command, _ []string) error {
if err != nil {
return err
}
delete(listOptions.Filter, "all") // list does not support --filter all
filteredVolumes, err := registry.ContainerEngine().VolumeList(context.Background(), listOptions)
if err != nil {
return err

View File

@@ -42,6 +42,14 @@ var _ = Describe("Podman volume prune", func() {
Expect(session.OutputToString()).To(ContainSubstring("named_vol"))
})
It("podman volume prune --all removes all unused volumes", func() {
podmanTest.PodmanExitCleanly("volume", "create", "prune_all_test")
podmanTest.PodmanExitCleanly("volume", "prune", "--all", "--force")
session := podmanTest.PodmanExitCleanly("volume", "ls")
Expect(session.OutputToStringArray()).To(HaveLen(1))
})
It("podman volume prune --filter all=true removes all unused volumes", func() {
podmanTest.PodmanExitCleanly("volume", "create", "prune_filter_all_test")
podmanTest.PodmanExitCleanly("volume", "prune", "--filter", "all=true", "--force")
@@ -50,6 +58,10 @@ var _ = Describe("Podman volume prune", func() {
Expect(session.OutputToStringArray()).To(HaveLen(1))
})
It("podman volume prune --filter all=true does not crash without --force", func() {
podmanTest.PodmanExitCleanly("volume", "prune", "--filter", "all=true")
})
It("podman prune volume --filter until", func() {
podmanTest.PodmanExitCleanly("volume", "create", "--label", "label1=value1", "myvol1")