Use imageParts.normalizedReference in normalizeTag

This is another step to using reference values instead of strings here.

CHANGES BEHAVIOR: docker.io/busybox is now normalized to docker.io/library/busybox.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač 2019-01-09 21:35:04 +01:00
parent 1c19d19c6e
commit e060a19c87
2 changed files with 9 additions and 2 deletions

View File

@ -459,13 +459,19 @@ func normalizeTag(tag string) (string, error) {
return "", err return "", err
} }
// If the input doesn't specify a registry, set the registry to localhost // If the input doesn't specify a registry, set the registry to localhost
var ref reference.Named
if !decomposedTag.hasRegistry { if !decomposedTag.hasRegistry {
ref, err := decomposedTag.referenceWithRegistry(DefaultLocalRegistry) ref, err = decomposedTag.referenceWithRegistry(DefaultLocalRegistry)
if err != nil { if err != nil {
return "", err return "", err
} }
tag = ref.String() } else {
ref, err = decomposedTag.normalizedReference()
if err != nil {
return "", err
} }
}
tag = ref.String()
// If the input does not have a tag, we need to add one (latest) // If the input does not have a tag, we need to add one (latest)
if !decomposedTag.isTagged { if !decomposedTag.isTagged {
tag = fmt.Sprintf("%s:%s", tag, decomposedTag.tag) tag = fmt.Sprintf("%s:%s", tag, decomposedTag.tag)

View File

@ -268,6 +268,7 @@ func TestNormalizeTag(t *testing.T) {
{"example.com/busybox:notlatest" + digestSuffix, "example.com/busybox:notlatest" + digestSuffix}, // Qualified name:tag@digest {"example.com/busybox:notlatest" + digestSuffix, "example.com/busybox:notlatest" + digestSuffix}, // Qualified name:tag@digest
{"busybox:latest", "localhost/busybox:latest"}, // Unqualified name-only {"busybox:latest", "localhost/busybox:latest"}, // Unqualified name-only
{"ns/busybox:latest", "localhost/ns/busybox:latest"}, // Unqualified with a dot-less namespace {"ns/busybox:latest", "localhost/ns/busybox:latest"}, // Unqualified with a dot-less namespace
{"docker.io/busybox:latest", "docker.io/library/busybox:latest"}, // docker.io without /library/
} { } {
res, err := normalizeTag(c.input) res, err := normalizeTag(c.input)
if c.expected == "" { if c.expected == "" {