Merge pull request #15197 from vrothberg/fix-15006

podman rmi: improve error message for build containers
This commit is contained in:
openshift-ci[bot]
2022-08-04 17:47:03 +00:00
committed by GitHub
7 changed files with 18 additions and 10 deletions

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/containernetworking/cni v1.1.2
github.com/containernetworking/plugins v1.1.1
github.com/containers/buildah v1.26.1-0.20220716095526-d31d27c357ab
github.com/containers/common v0.49.1-0.20220729221035-246800047d46
github.com/containers/common v0.49.2-0.20220804143628-dc97077782d5
github.com/containers/conmon v2.0.20+incompatible
github.com/containers/image/v5 v5.22.0
github.com/containers/ocicrypt v1.1.5

4
go.sum
View File

@ -395,8 +395,8 @@ github.com/containernetworking/plugins v1.1.1/go.mod h1:Sr5TH/eBsGLXK/h71HeLfX19
github.com/containers/buildah v1.26.1-0.20220716095526-d31d27c357ab h1:NeI0DOkTf3Tn4OpdjMhMubAfTPs2oCO5jUY5wnpv4qk=
github.com/containers/buildah v1.26.1-0.20220716095526-d31d27c357ab/go.mod h1:iVtQtU6a+pbETBqIzg0oAWW3gTR1ItrAihJpLFFppmA=
github.com/containers/common v0.48.1-0.20220715075726-2ac10faca05a/go.mod h1:1dA7JPGoSi83kjf5H4NIrGANyLOULyvFqV1bwvYFEek=
github.com/containers/common v0.49.1-0.20220729221035-246800047d46 h1:BNNV+JlPYSmaa9rTapL9kh2JZrg7hmWwi/VrIY/KH1E=
github.com/containers/common v0.49.1-0.20220729221035-246800047d46/go.mod h1:ueM5hT0itKqCQvVJDs+EtjornAQtrHYxQJzP2gxeGIg=
github.com/containers/common v0.49.2-0.20220804143628-dc97077782d5 h1:bOdbfjiOvj5n51dyeo8LF3qAtvaiflS13q70Cx4NA40=
github.com/containers/common v0.49.2-0.20220804143628-dc97077782d5/go.mod h1:ueM5hT0itKqCQvVJDs+EtjornAQtrHYxQJzP2gxeGIg=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/image/v5 v5.21.2-0.20220712113758-29aec5f7bbbf/go.mod h1:0+N0ZM9mgMmoZZc6uNcgnEsbX85Ne7b29cIW5lqWwVU=

View File

@ -259,8 +259,8 @@ Labels.created_at | 20[0-9-]\\\+T[0-9:]\\\+Z
run_podman 2 rmi -a
is "$output" "Error: 2 errors occurred:
.** image used by .*: image is in use by a container
.** image used by .*: image is in use by a container"
.** image used by .*: image is in use by a container: consider listing external containers and force-removing image
.** image used by .*: image is in use by a container: consider listing external containers and force-removing image"
run_podman rmi -af
is "$output" "Untagged: $IMAGE
@ -292,7 +292,7 @@ Deleted: $pauseID" "infra images gets removed as well"
pauseID=$output
run_podman 2 rmi $pauseImage
is "$output" "Error: image used by .* image is in use by a container"
is "$output" "Error: image used by .* image is in use by a container: consider listing external containers and force-removing image"
run_podman rmi -f $pauseImage
is "$output" "Untagged: $pauseImage

View File

@ -470,6 +470,9 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
}
if _, err := i.runtime.store.DeleteImage(i.ID(), true); handleError(err) != nil {
if errors.Is(err, storage.ErrImageUsedByContainer) {
err = fmt.Errorf("%w: consider listing external containers and force-removing image", err)
}
return processedIDs, err
}
report.Untagged = append(report.Untagged, i.Names()...)
@ -478,6 +481,11 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
report.Removed = true
}
// Do not delete any parents if NoPrune is true
if options.NoPrune {
return processedIDs, nil
}
// Check if can remove the parent image.
if parent == nil {
return processedIDs, nil
@ -495,7 +503,6 @@ func (i *Image) removeRecursive(ctx context.Context, rmMap map[string]*RemoveIma
if !danglingParent {
return processedIDs, nil
}
// Recurse into removing the parent.
return parent.removeRecursive(ctx, rmMap, processedIDs, "", options)
}

View File

@ -608,6 +608,8 @@ type RemoveImagesOptions struct {
// much space was freed. However, computing the size of an image is
// comparatively expensive, so it is made optional.
WithSize bool
// NoPrune will not remove dangling images
NoPrune bool
}
// RemoveImages removes images specified by names. If no names are specified,
@ -653,7 +655,6 @@ func (r *Runtime) RemoveImages(ctx context.Context, names []string, options *Rem
toDelete := []string{}
// Look up images in the local containers storage and fill out
// toDelete and the deleteMap.
switch {
case len(names) > 0:
// prepare lookupOptions

View File

@ -1,4 +1,4 @@
package version
// Version is the version of the build.
const Version = "0.49.1-dev"
const Version = "0.49.2-dev"

2
vendor/modules.txt vendored
View File

@ -114,7 +114,7 @@ github.com/containers/buildah/pkg/rusage
github.com/containers/buildah/pkg/sshagent
github.com/containers/buildah/pkg/util
github.com/containers/buildah/util
# github.com/containers/common v0.49.1-0.20220729221035-246800047d46
# github.com/containers/common v0.49.2-0.20220804143628-dc97077782d5
## explicit
github.com/containers/common/libimage
github.com/containers/common/libimage/define