diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-05-24 09:13:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-24 09:13:48 -0400 |
commit | a1ec21dac104d811d5a22a663181a503177d5187 (patch) | |
tree | 1f61ba0605393d653714e9a9db0a9979ea194704 /pkg | |
parent | d537cf1de3d457823754ea68d4983944f8140837 (diff) | |
parent | 1021afb6b0a06701e0cc778a4f5d0c88b9042a9b (diff) | |
download | podman-a1ec21dac104d811d5a22a663181a503177d5187.tar.gz podman-a1ec21dac104d811d5a22a663181a503177d5187.tar.bz2 podman-a1ec21dac104d811d5a22a663181a503177d5187.zip |
Merge pull request #14337 from openshift-cherrypick-robot/cherry-pick-14294-to-v4.1
[v4.1] fix compat image resolution
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/utils/images.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go index 7154f5616..433231f59 100644 --- a/pkg/api/handlers/utils/images.go +++ b/pkg/api/handlers/utils/images.go @@ -26,21 +26,26 @@ func NormalizeToDockerHub(r *http.Request, nameOrID string) (string, error) { return nameOrID, nil } - // Try to lookup the input to figure out if it was an ID or not. runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) - img, _, err := runtime.LibimageRuntime().LookupImage(nameOrID, nil) + + // The candidate may resolve to a local non-Docker Hub image, such as + // 'busybox' -> 'registry.com/busybox'. + img, candidate, err := runtime.LibimageRuntime().LookupImage(nameOrID, nil) if err != nil { if errors.Cause(err) != storage.ErrImageUnknown { return "", fmt.Errorf("normalizing name for compat API: %v", err) } + // If the image could not be resolved locally, set the + // candidate back to the input. + candidate = nameOrID } else if strings.HasPrefix(img.ID(), strings.TrimPrefix(nameOrID, "sha256:")) { return img.ID(), nil } // No ID, so we can normalize. - named, err := reference.ParseNormalizedNamed(nameOrID) + named, err := reference.ParseNormalizedNamed(candidate) if err != nil { - return "", fmt.Errorf("normalizing name for compat API: %v", err) + return "", fmt.Errorf("normalizing name %q (orig: %q) for compat API: %v", candidate, nameOrID, err) } return named.String(), nil |