summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-09-16 12:12:07 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-09-17 12:23:58 +0200
commitecae5f7adeb1acea9c090c3d6c43f7470f33ac84 (patch)
tree5e17fab239a3c698a027733b7eba5ffcb0cacbe1
parent8d7e7954546efb344d677e0c3c86d9d045a3de4f (diff)
downloadpodman-ecae5f7adeb1acea9c090c3d6c43f7470f33ac84.tar.gz
podman-ecae5f7adeb1acea9c090c3d6c43f7470f33ac84.tar.bz2
podman-ecae5f7adeb1acea9c090c3d6c43f7470f33ac84.zip
image list: return all associated names
Always return all associated names / repo tags of an image and fix a bug with malformed repo tags. Previously, Podman returned all names only with `--all` but this flag only instructs to list intermediate images and should not alter associated names. With `--all` Podman queried the repo tags of an image which splits all *tagged* names into repository and tag which is then reassembled to eventually be parsed again in the frontend. Lot's of redundant CPU heat and buggy as the reassembly didn't consider digests which ultimately broke parsing in the frontend. Fixes: #7651 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--cmd/podman/images/list.go15
-rw-r--r--libpod/image/utils.go27
-rw-r--r--pkg/domain/infra/abi/images_list.go24
-rw-r--r--test/e2e/images_test.go32
4 files changed, 48 insertions, 50 deletions
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 043871a8c..ffb341fc4 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -184,13 +184,26 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
for _, e := range imageS {
var h imageReporter
if len(e.RepoTags) > 0 {
+ tagged := []imageReporter{}
+ untagged := []imageReporter{}
for _, tag := range e.RepoTags {
h.ImageSummary = *e
h.Repository, h.Tag, err = tokenRepoTag(tag)
if err != nil {
return nil, errors.Wrapf(err, "error parsing repository tag %q:", tag)
}
- imgs = append(imgs, h)
+ if h.Tag == "<none>" {
+ untagged = append(untagged, h)
+ } else {
+ tagged = append(tagged, h)
+ }
+ }
+ // Note: we only want to display "<none>" if we
+ // couldn't find any tagged name in RepoTags.
+ if len(tagged) > 0 {
+ imgs = append(imgs, tagged...)
+ } else {
+ imgs = append(imgs, untagged[0])
}
} else {
h.ImageSummary = *e
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
index b7ea63c66..918314476 100644
--- a/libpod/image/utils.go
+++ b/libpod/image/utils.go
@@ -86,33 +86,6 @@ func hasTransport(image string) bool {
return strings.Contains(image, "://")
}
-// ReposToMap parses the specified repotags and returns a map with repositories
-// as keys and the corresponding arrays of tags or digests-as-strings as values.
-func ReposToMap(names []string) (map[string][]string, error) {
- // map format is repo -> []tag-or-digest
- repos := make(map[string][]string)
- for _, name := range names {
- var repository, tag string
- if len(name) > 0 {
- named, err := reference.ParseNormalizedNamed(name)
- if err != nil {
- return nil, err
- }
- repository = named.Name()
- if ref, ok := named.(reference.NamedTagged); ok {
- tag = ref.Tag()
- } else if ref, ok := named.(reference.Canonical); ok {
- tag = ref.Digest().String()
- }
- }
- repos[repository] = append(repos[repository], tag)
- }
- if len(repos) == 0 {
- repos["<none>"] = []string{"<none>"}
- }
- return repos, nil
-}
-
// GetAdditionalTags returns a list of reference.NamedTagged for the
// additional tags given in images
func GetAdditionalTags(images []string) ([]reference.NamedTagged, error) {
diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go
index 7ec84246d..3e47dc67a 100644
--- a/pkg/domain/infra/abi/images_list.go
+++ b/pkg/domain/infra/abi/images_list.go
@@ -23,33 +23,13 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
summaries := []*entities.ImageSummary{}
for _, img := range images {
- var repoTags []string
- if opts.All {
- pairs, err := libpodImage.ReposToMap(img.Names())
- if err != nil {
- return nil, err
- }
-
- for repo, tags := range pairs {
- for _, tag := range tags {
- repoTags = append(repoTags, repo+":"+tag)
- }
- }
- } else {
- repoTags, err = img.RepoTags()
- if err != nil {
- return nil, err
- }
- }
-
digests := make([]string, len(img.Digests()))
for j, d := range img.Digests() {
digests[j] = string(d)
}
e := entities.ImageSummary{
- ID: img.ID(),
-
+ ID: img.ID(),
ConfigDigest: string(img.ConfigDigest),
Created: img.Created().Unix(),
Dangling: img.Dangling(),
@@ -61,7 +41,7 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
ReadOnly: img.IsReadOnly(),
SharedSize: 0,
VirtualSize: img.VirtualSize,
- RepoTags: repoTags,
+ RepoTags: img.Names(), // may include tags and digests
}
e.Labels, _ = img.Labels(context.TODO())
diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go
index a615a9f99..ddf2e20b8 100644
--- a/test/e2e/images_test.go
+++ b/test/e2e/images_test.go
@@ -241,6 +241,38 @@ WORKDIR /test
Expect(result.OutputToStringArray()).Should(HaveLen(0), "dangling image output: %q", result.OutputToString())
})
+ It("podman pull by digest and list --all", func() {
+ // Prevent regressing on issue #7651.
+ digestPullAndList := func(noneTag bool) {
+ session := podmanTest.Podman([]string{"pull", ALPINEAMD64DIGEST})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ result := podmanTest.Podman([]string{"images", "--all", ALPINEAMD64DIGEST})
+ result.WaitWithDefaultTimeout()
+ Expect(result).Should(Exit(0))
+
+ found, _ := result.GrepString("<none>")
+ if noneTag {
+ Expect(found).To(BeTrue())
+ } else {
+ Expect(found).To(BeFalse())
+ }
+ }
+ // No "<none>" tag as tagged alpine instances should be present.
+ session := podmanTest.Podman([]string{"pull", ALPINELISTTAG})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ digestPullAndList(false)
+
+ // Now remove all images, re-pull by digest and check for the "<none>" tag.
+ session = podmanTest.Podman([]string{"rmi", "-af"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+
+ digestPullAndList(true)
+ })
+
It("podman check for image with sha256: prefix", func() {
session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()