From 5ea050fc1211e6f42956f1cb5fe4c62e3d97e06e Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 11 Dec 2017 16:02:54 -0500 Subject: [PATCH] Handle truncated IDs in imageService.ResolveNames() Have ResolveNames() check if the value that it's been given is a truncated version of the ID of a locally-available image, and if it is, return the value as it was given. Signed-off-by: Nalin Dahyabhai --- pkg/storage/image.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/storage/image.go b/pkg/storage/image.go index a3916f20..5994d952 100644 --- a/pkg/storage/image.go +++ b/pkg/storage/image.go @@ -18,6 +18,10 @@ import ( digest "github.com/opencontainers/go-digest" ) +const ( + minimumTruncatedIDLength = 3 +) + var ( // ErrCannotParseImageID is returned when we try to ResolveNames for an image ID ErrCannotParseImageID = errors.New("cannot parse an image ID") @@ -512,6 +516,14 @@ func splitDockerDomain(name string) (domain, remainder string) { } func (svc *imageService) ResolveNames(imageName string) ([]string, error) { + // _Maybe_ it's a truncated image ID. Don't prepend a registry name, then. + if len(imageName) >= minimumTruncatedIDLength && svc.store != nil { + if img, err := svc.store.Image(imageName); err == nil && img != nil && strings.HasPrefix(img.ID, imageName) { + // It's a truncated version of the ID of an image that's present in local storage; + // we need to expand it. + return []string{img.ID}, nil + } + } // This to prevent any image ID to go through this routine _, err := reference.ParseNormalizedNamed(imageName) if err != nil {