Merge pull request #19891 from edsantiago/run_rmi_warn

run --rmi: "cannot remove" is a warning, not an error
This commit is contained in:
Daniel J Walsh
2023-09-09 10:20:49 -04:00
committed by GitHub
2 changed files with 8 additions and 4 deletions

View File

@ -13,10 +13,10 @@ import (
"github.com/containers/podman/v4/cmd/podman/utils" "github.com/containers/podman/v4/cmd/podman/utils"
"github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/errorhandling"
"github.com/containers/podman/v4/pkg/rootless" "github.com/containers/podman/v4/pkg/rootless"
"github.com/containers/podman/v4/pkg/specgen" "github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgenutil" "github.com/containers/podman/v4/pkg/specgenutil"
"github.com/containers/storage/types"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/term" "golang.org/x/term"
@ -226,8 +226,12 @@ func run(cmd *cobra.Command, args []string) error {
} }
if runRmi { if runRmi {
_, rmErrors := registry.ImageEngine().Remove(registry.GetContext(), []string{imageName}, entities.ImageRemoveOptions{}) _, rmErrors := registry.ImageEngine().Remove(registry.GetContext(), []string{imageName}, entities.ImageRemoveOptions{})
if len(rmErrors) > 0 { for _, err := range rmErrors {
logrus.Errorf("%s", errorhandling.JoinErrors(rmErrors)) // ImageUnknown would be a super-unlikely race
if !errors.Is(err, types.ErrImageUnknown) {
// Typical case: ErrImageUsedByContainer
logrus.Warn(err)
}
} }
} }
if cmd.Flag("gpus").Changed { if cmd.Flag("gpus").Changed {

View File

@ -181,7 +181,7 @@ echo $rand | 0 | $rand
run_podman image exists $NONLOCAL_IMAGE run_podman image exists $NONLOCAL_IMAGE
# Now try running with --rmi : it should succeed, but not remove the image # Now try running with --rmi : it should succeed, but not remove the image
run_podman 0+e run --rmi --rm $NONLOCAL_IMAGE /bin/true run_podman 0+w run --rmi --rm $NONLOCAL_IMAGE /bin/true
is "$output" ".*image is in use by a container" "--rmi should warn that the image was not removed" is "$output" ".*image is in use by a container" "--rmi should warn that the image was not removed"
run_podman image exists $NONLOCAL_IMAGE run_podman image exists $NONLOCAL_IMAGE