Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use local image name for pull policy checks #2908

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

vrothberg
Copy link
Member

Some pull policies require to first look up a local image and compare
that to the remote counter part. When looking up the remote image, we
need to make sure to use the name of the local image, if it exists.

This fixes a bug where a short name resolved to an image with the
"localhost/" prefix. This prefix is only used for local image look ups
via shortnames.ResolveLocally. Hence, when looking up the remote
counter part, we must preserve this prefix.

Fixes: #2904
Signed-off-by: Valentin Rothberg [email protected]

Some pull policies require to first look up a local image and compare
that to the remote counter part.  When looking up the remote image, we
need to make sure to use the name of the local image, if it exists.

This fixes a bug where a short name resolved to an image with the
"localhost/" prefix.  This prefix is only used for local image look ups
via `shortnames.ResolveLocally`.  Hence, when looking up the remote
counter part, we must preserve this prefix.

Fixes: containers#2904
Signed-off-by: Valentin Rothberg <[email protected]>
@vrothberg
Copy link
Member Author

@mtrmac @rhatdan @TomSweeneyRedHat PTAL

@rhatdan
Copy link
Member

rhatdan commented Jan 14, 2021

LGTM
Yes we need to get this into podman 3.0

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit b595a98 into containers:master Jan 14, 2021
Copy link
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, with things like PullIfNewer we should always only use a remote image from the same registry as the local one.

if localImageRef != nil {
fromImage = localImageName
}

resolved, err := shortnames.Resolve(systemContext, fromImage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now stuttering and hard to follow.

How about

if options.PullPolicy == PullNever && localImage == nil { /* fail*/ }
if localImage != nil {
   // the three checks
}

@@ -145,7 +145,7 @@ func resolveImage(ctx context.Context, systemContext *types.SystemContext, store
}
}

localImageRef, _, localImage, err := resolveLocalImage(systemContext, store, options)
localImageRef, _, localImageName, localImage, err := resolveLocalImage(systemContext, store, options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated? This is the only caller, yet we ignore the second return value. It should be dropped, then.

// If we found a local image, we must use it's name.
// See #2904.
if localImageRef != nil {
fromImage = localImageName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Non-blocking: It might be useful to add a debug log if fromImage != localImageName, so that users can figure out where the fully-qualified variant came from.)

@vrothberg vrothberg deleted the fix-2904 branch January 14, 2021 15:04
// See #2904.
if localImageRef != nil {
fromImage = localImageName
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat workaround, hadn't thought about trying this.

TomSweeneyRedHat added a commit to TomSweeneyRedHat/buildah that referenced this pull request Jan 14, 2021
…9 branch

Cherry pick @vrothberg's "use local image name for pull policy checks" containers#2908
and update the cirrus and git validations so the test will run on this new(ish)
branch.  From @vrothberg:

Some pull policies require to first look up a local image and compare
that to the remote counter part. When looking up the remote image, we
need to make sure to use the name of the local image, if it exists.

This fixes a bug where a short name resolved to an image with the
"localhost/" prefix. This prefix is only used for local image look ups
via shortnames.ResolveLocally. Hence, when looking up the remote
counter part, we must preserve this prefix.

Fixes: containers#2904

Signed-off-by: TomSweeneyRedHat <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Local Image not found during build - Buildah v1.19
7 participants