libimage: pull: normalize docker-daemon
Normalize images pulled from the docker-daemon transport to docker.io and not to localhost. That preserves previous behavior of Podman. Also fix a parsing bug in the pull code that was revealed while testing the changes; parsing errors should be returned if there is a matching transport without falling through to pulling the input string as an image from a registry. Context: containers/podman/issues/10998 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
parent
8f961bd2c1
commit
369aaa4178
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
registryTransport "github.com/containers/image/v5/docker"
|
registryTransport "github.com/containers/image/v5/docker"
|
||||||
dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
|
dockerArchiveTransport "github.com/containers/image/v5/docker/archive"
|
||||||
|
dockerDaemonTransport "github.com/containers/image/v5/docker/daemon"
|
||||||
"github.com/containers/image/v5/docker/reference"
|
"github.com/containers/image/v5/docker/reference"
|
||||||
ociArchiveTransport "github.com/containers/image/v5/oci/archive"
|
ociArchiveTransport "github.com/containers/image/v5/oci/archive"
|
||||||
ociTransport "github.com/containers/image/v5/oci/layout"
|
ociTransport "github.com/containers/image/v5/oci/layout"
|
||||||
|
@ -55,6 +56,13 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
|
||||||
var possiblyUnqualifiedName string // used for short-name resolution
|
var possiblyUnqualifiedName string // used for short-name resolution
|
||||||
ref, err := alltransports.ParseImageName(name)
|
ref, err := alltransports.ParseImageName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Check whether `name` points to a transport. If so, we
|
||||||
|
// return the error. Otherwise we assume that `name` refers to
|
||||||
|
// an image on a registry (e.g., "fedora").
|
||||||
|
if alltransports.TransportFromImageName(name) != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// If the image clearly refers to a local one, we can look it up directly.
|
// If the image clearly refers to a local one, we can look it up directly.
|
||||||
// In fact, we need to since they are not parseable.
|
// In fact, we need to since they are not parseable.
|
||||||
if strings.HasPrefix(name, "sha256:") || (len(name) == 64 && !strings.ContainsAny(name, "/.:@")) {
|
if strings.HasPrefix(name, "sha256:") || (len(name) == 64 && !strings.ContainsAny(name, "/.:@")) {
|
||||||
|
@ -169,6 +177,15 @@ func (r *Runtime) copyFromDefault(ctx context.Context, ref types.ImageReference,
|
||||||
var storageName, imageName string
|
var storageName, imageName string
|
||||||
switch ref.Transport().Name() {
|
switch ref.Transport().Name() {
|
||||||
|
|
||||||
|
case dockerDaemonTransport.Transport.Name():
|
||||||
|
// Normalize to docker.io if needed (see containers/podman/issues/10998).
|
||||||
|
named, err := reference.ParseNormalizedNamed(ref.StringWithinTransport())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
imageName = named.String()
|
||||||
|
storageName = imageName
|
||||||
|
|
||||||
case ociTransport.Transport.Name():
|
case ociTransport.Transport.Name():
|
||||||
split := strings.SplitN(ref.StringWithinTransport(), ":", 2)
|
split := strings.SplitN(ref.StringWithinTransport(), ":", 2)
|
||||||
storageName = toLocalImageName(split[0])
|
storageName = toLocalImageName(split[0])
|
||||||
|
|
|
@ -19,6 +19,12 @@ func TestPull(t *testing.T) {
|
||||||
pullOptions := &PullOptions{}
|
pullOptions := &PullOptions{}
|
||||||
pullOptions.Writer = os.Stdout
|
pullOptions.Writer = os.Stdout
|
||||||
|
|
||||||
|
// Make sure that parsing errors of the daemon transport are returned
|
||||||
|
// and that we do not fallthrough attempting to pull the specified
|
||||||
|
// string as an image from a registry.
|
||||||
|
_, err := runtime.Pull(ctx, "docker-daemon:alpine", config.PullPolicyAlways, pullOptions)
|
||||||
|
require.Error(t, err, "return parsing error from daemon transport")
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
input string
|
input string
|
||||||
expectError bool
|
expectError bool
|
||||||
|
|
Loading…
Reference in New Issue