mirror of
https://github.com/containers/podman.git
synced 2025-09-26 16:25:00 +08:00
create: support images with invalid platform
Much to my regret, there is a number of images in the wild with invalid platforms breaking the platform checks in libimage that want to make sure that a local image is matching the expected platform. Imagine a `podman run --arch=arm64 fedora` with a local amd64 fedora image. We really shouldn't use the local one in this case and pull down the arm64 one. The strict platform checks in libimage in combination with invalid platforms in images surfaced in Podman being able to pull an image but failing to look it up in subsequent presence checks. A `podman run` would hence pull such an image but fail to create the container. Support images with invalid platforms by vendoring the latest HEAD from containers/common. Also remove the partially implemented pull-policy logic from Podman and let libimage handle that entirely. However, whenever --arch, --os or --platform are specified, the pull policy will be forced to "newer". This way, we pessimistically assume that the local image has an invalid platform and we reach out to the registry. If there's a newer image (i.e., one with a different digest), we'll pull it down. Please note that most of the logic has either already been implemented in libimage or been moved down which allows for removing some clutter from Podman. [NO TESTS NEEDED] since c/common has new tests. Podman can rely on the existing tests. Fixes: #10648 Fixes: #10682 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
48
vendor/github.com/containers/common/libimage/pull.go
generated
vendored
48
vendor/github.com/containers/common/libimage/pull.go
generated
vendored
@ -105,6 +105,20 @@ func (r *Runtime) Pull(ctx context.Context, name string, pullPolicy config.PullP
|
||||
r.writeEvent(&Event{ID: "", Name: name, Time: time.Now(), Type: EventTypeImagePull})
|
||||
}
|
||||
|
||||
// Some callers may set the platform via the system context at creation
|
||||
// time of the runtime. We need this information to decide whether we
|
||||
// need to enforce pulling from a registry (see
|
||||
// containers/podman/issues/10682).
|
||||
if options.Architecture == "" {
|
||||
options.Architecture = r.systemContext.ArchitectureChoice
|
||||
}
|
||||
if options.OS == "" {
|
||||
options.OS = r.systemContext.OSChoice
|
||||
}
|
||||
if options.Variant == "" {
|
||||
options.Variant = r.systemContext.VariantChoice
|
||||
}
|
||||
|
||||
var (
|
||||
pulledImages []string
|
||||
pullError error
|
||||
@ -333,7 +347,7 @@ func (r *Runtime) copyFromRegistry(ctx context.Context, ref types.ImageReference
|
||||
// from a registry. On successful pull it returns the used fully-qualified
|
||||
// name that can later be used to look up the image in the local containers
|
||||
// storage.
|
||||
func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName string, pullPolicy config.PullPolicy, options *PullOptions) ([]string, error) {
|
||||
func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName string, pullPolicy config.PullPolicy, options *PullOptions) ([]string, error) { //nolint:gocyclo
|
||||
// Sanity check.
|
||||
if err := pullPolicy.Validate(); err != nil {
|
||||
return nil, err
|
||||
@ -349,11 +363,41 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str
|
||||
// resolved name for pulling. Assume we're doing a `pull foo`.
|
||||
// If there's already a local image "localhost/foo", then we should
|
||||
// attempt pulling that instead of doing the full short-name dance.
|
||||
localImage, resolvedImageName, err = r.LookupImage(imageName, nil)
|
||||
lookupOptions := &LookupImageOptions{
|
||||
// NOTE: we must ignore the platform of a local image when
|
||||
// doing lookups. Some images set an incorrect or even invalid
|
||||
// platform (see containers/podman/issues/10682). Doing the
|
||||
// lookup while ignoring the platform checks prevents
|
||||
// redundantly downloading the same image.
|
||||
IgnorePlatform: true,
|
||||
}
|
||||
localImage, resolvedImageName, err = r.LookupImage(imageName, lookupOptions)
|
||||
if err != nil && errors.Cause(err) != storage.ErrImageUnknown {
|
||||
logrus.Errorf("Looking up %s in local storage: %v", imageName, err)
|
||||
}
|
||||
|
||||
// If the local image is corrupted, we need to repull it.
|
||||
if localImage != nil {
|
||||
if err := localImage.isCorrupted(imageName); err != nil {
|
||||
logrus.Error(err)
|
||||
localImage = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Unless the pull policy is "always", we must pessimistically assume
|
||||
// that the local image has an invalid architecture (see
|
||||
// containers/podman/issues/10682). Hence, whenever the user requests
|
||||
// a custom platform, set the pull policy to "always" to make sure
|
||||
// we're pulling down the image.
|
||||
//
|
||||
// NOTE that this is will even override --pull={false,never}. This is
|
||||
// very likely a bug but a consistent one in Podman/Buildah and should
|
||||
// be addressed at a later point.
|
||||
if pullPolicy != config.PullPolicyAlways && len(options.Architecture)+len(options.OS)+len(options.Variant) > 0 {
|
||||
logrus.Debugf("Enforcing pull policy to %q to support custom platform (arch: %q, os: %q, variant: %q)", "always", options.Architecture, options.OS, options.Variant)
|
||||
pullPolicy = config.PullPolicyAlways
|
||||
}
|
||||
|
||||
if pullPolicy == config.PullPolicyNever {
|
||||
if localImage != nil {
|
||||
logrus.Debugf("Pull policy %q but no local image has been found for %s", pullPolicy, imageName)
|
||||
|
Reference in New Issue
Block a user