mirror of https://github.com/containers/podman.git
Parse fq name correctly for images
When parsing a string name for repo and tag (for images output), we should be using parsenormalizedname and reference.Canonical to get the proper output. Resolves: #2175 Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
parent
ee27c39f85
commit
f29a11c201
|
@ -247,8 +247,12 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all specified repo:tag pairs and print them separately
|
// get all specified repo:tag pairs and print them separately
|
||||||
|
repopairs, err := image.ReposToMap(img.Names())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error finding tag/digest for %s", img.ID())
|
||||||
|
}
|
||||||
outer:
|
outer:
|
||||||
for repo, tags := range image.ReposToMap(img.Names()) {
|
for repo, tags := range repopairs {
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
size, err := img.Size(ctx)
|
size, err := img.Size(ctx)
|
||||||
var sizeStr string
|
var sizeStr string
|
||||||
|
|
|
@ -87,22 +87,29 @@ func hasTransport(image string) bool {
|
||||||
|
|
||||||
// ReposToMap parses the specified repotags and returns a map with repositories
|
// ReposToMap parses the specified repotags and returns a map with repositories
|
||||||
// as keys and the corresponding arrays of tags as values.
|
// as keys and the corresponding arrays of tags as values.
|
||||||
func ReposToMap(repotags []string) map[string][]string {
|
func ReposToMap(repotags []string) (map[string][]string, error) {
|
||||||
// map format is repo -> tag
|
// map format is repo -> tag
|
||||||
repos := make(map[string][]string)
|
repos := make(map[string][]string)
|
||||||
for _, repo := range repotags {
|
for _, repo := range repotags {
|
||||||
var repository, tag string
|
var repository, tag string
|
||||||
if len(repo) > 0 {
|
if len(repo) > 0 {
|
||||||
li := strings.LastIndex(repo, ":")
|
named, err := reference.ParseNormalizedNamed(repo)
|
||||||
repository = repo[0:li]
|
repository = named.Name()
|
||||||
tag = repo[li+1:]
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
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)
|
repos[repository] = append(repos[repository], tag)
|
||||||
}
|
}
|
||||||
if len(repos) == 0 {
|
if len(repos) == 0 {
|
||||||
repos["<none>"] = []string{"<none>"}
|
repos["<none>"] = []string{"<none>"}
|
||||||
}
|
}
|
||||||
return repos
|
return repos, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAdditionalTags returns a list of reference.NamedTagged for the
|
// GetAdditionalTags returns a list of reference.NamedTagged for the
|
||||||
|
|
Loading…
Reference in New Issue