summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-17 15:19:45 -0400
committerGitHub <noreply@github.com>2020-04-17 15:19:45 -0400
commitbd8a0b08cdea5f15d6033b24038ba71aef1f8962 (patch)
tree581e283021a0edff9dfd89be73ddd7ccceb42b1d /libpod
parentba289dcd79e3a2b5ec5dc02bd8adb84c93bef577 (diff)
parentd8321363498c349647409dea1b6e15f8cf0ac17a (diff)
downloadpodman-bd8a0b08cdea5f15d6033b24038ba71aef1f8962.tar.gz
podman-bd8a0b08cdea5f15d6033b24038ba71aef1f8962.tar.bz2
podman-bd8a0b08cdea5f15d6033b24038ba71aef1f8962.zip
Merge pull request #5548 from kunalkushwaha/image-prune
image prune skips images with child images.
Diffstat (limited to 'libpod')
-rw-r--r--libpod/image/image.go24
-rw-r--r--libpod/image/prune.go22
2 files changed, 38 insertions, 8 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 80cc6f15a..7198a42a3 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -32,10 +32,10 @@ import (
"github.com/containers/libpod/pkg/registries"
"github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
- "github.com/opencontainers/go-digest"
+ digest "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
- "github.com/opentracing/opentracing-go"
+ opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -847,6 +847,26 @@ func (i *Image) Dangling() bool {
return len(i.Names()) == 0
}
+// Intermediate returns true if the image is cache or intermediate image.
+// Cache image has parent and child.
+func (i *Image) Intermediate(ctx context.Context) (bool, error) {
+ parent, err := i.IsParent(ctx)
+ if err != nil {
+ return false, err
+ }
+ if !parent {
+ return false, nil
+ }
+ img, err := i.GetParent(ctx)
+ if err != nil {
+ return false, err
+ }
+ if img != nil {
+ return true, nil
+ }
+ return false, nil
+}
+
// Labels returns the image's labels
func (i *Image) Labels(ctx context.Context) (map[string]string, error) {
imgInspect, err := i.imageInspectInfo(ctx)
diff --git a/libpod/image/prune.go b/libpod/image/prune.go
index 3afff22af..3b4ea74c4 100644
--- a/libpod/image/prune.go
+++ b/libpod/image/prune.go
@@ -57,7 +57,7 @@ func generatePruneFilterFuncs(filter, filterValue string) (ImageFilter, error) {
}
// GetPruneImages returns a slice of images that have no names/unused
-func (ir *Runtime) GetPruneImages(all bool, filterFuncs []ImageFilter) ([]*Image, error) {
+func (ir *Runtime) GetPruneImages(ctx context.Context, all bool, filterFuncs []ImageFilter) ([]*Image, error) {
var (
pruneImages []*Image
)
@@ -74,10 +74,6 @@ func (ir *Runtime) GetPruneImages(all bool, filterFuncs []ImageFilter) ([]*Image
}
}
- if len(i.Names()) == 0 {
- pruneImages = append(pruneImages, i)
- continue
- }
if all {
containers, err := i.Containers()
if err != nil {
@@ -85,8 +81,22 @@ func (ir *Runtime) GetPruneImages(all bool, filterFuncs []ImageFilter) ([]*Image
}
if len(containers) < 1 {
pruneImages = append(pruneImages, i)
+ continue
}
}
+
+ //skip the cache or intermediate images
+ intermediate, err := i.Intermediate(ctx)
+ if err != nil {
+ return nil, err
+ }
+ if intermediate {
+ continue
+ }
+
+ if i.Dangling() {
+ pruneImages = append(pruneImages, i)
+ }
}
return pruneImages, nil
}
@@ -111,7 +121,7 @@ func (ir *Runtime) PruneImages(ctx context.Context, all bool, filter []string) (
filterFuncs = append(filterFuncs, generatedFunc)
}
- pruneImages, err := ir.GetPruneImages(all, filterFuncs)
+ pruneImages, err := ir.GetPruneImages(ctx, all, filterFuncs)
if err != nil {
return nil, errors.Wrap(err, "unable to get images to prune")
}