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

libimage: pull: do not enforce pull if local image matches #1287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions libimage/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,26 @@ func (r *Runtime) copySingleImageFromRegistry(ctx context.Context, imageName str

customPlatform := len(options.Architecture)+len(options.OS)+len(options.Variant) > 0
if customPlatform && pullPolicy != config.PullPolicyAlways && pullPolicy != config.PullPolicyNever {
// Unless the pull policy is always/never, 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 "newer" to make sure we're pulling down the
// Unless the specified platform matches the local image, 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 "newer" to make sure we're pulling down the
// correct image.
//
// NOTE that this is will even override --pull={false,never}.
pullPolicy = config.PullPolicyNewer
logrus.Debugf("Enforcing pull policy to %q to pull custom platform (arch: %q, os: %q, variant: %q) - local image may mistakenly specify wrong platform", pullPolicy, options.Architecture, options.OS, options.Variant)
localImageMatches := false
Copy link
Member

Choose a reason for hiding this comment

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

Is the comment at line 507 correct? Just to be sure, --pull=never, should NEVER be overridden. If it is specified, we should not pull an image, we should only use the local image. It does look like we don't get in here on pull=never, and I'm hoping the comment is just off....

Copy link
Member Author

Choose a reason for hiding this comment

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

The comment is off. The condition above includes pullPolicy != config.PullPolicyNever.

I plan on massaging/simplifying this code in the future where I can cleanup comments as well.

if localImage != nil {
_, matches, err := localImage.matchesPlatform(ctx, options.OS, options.Architecture, options.Variant)
if err != nil {
return nil, err
}
localImageMatches = matches
}
if !localImageMatches {
pullPolicy = config.PullPolicyNewer
logrus.Debugf("Enforcing pull policy to %q to pull custom platform (arch: %q, os: %q, variant: %q) - local image may mistakenly specify wrong platform", pullPolicy, options.Architecture, options.OS, options.Variant)
}
}

if pullPolicy == config.PullPolicyNever {
Expand Down
23 changes: 23 additions & 0 deletions libimage/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"os"
goruntime "runtime"
"strings"
"testing"

"github.com/containers/common/pkg/config"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -94,6 +96,27 @@ func TestPullPlatforms(t *testing.T) {
require.NoError(t, err, "pull busybox")
require.Len(t, pulledImages, 1)

// Now re-pull with the platform explicitly set in the pull options. It
// should not repull an image (or perform a "newer" check) though but
// resolve to the local image.
//
// See containers/podman/issues/17063.
func() { // Anonymous function to make sure logrus is reset even on failure.
builder := strings.Builder{}
logrus.SetOutput(&builder)
logrus.SetLevel(logrus.DebugLevel)
defer builder.Reset()
defer logrus.SetOutput(os.Stderr)
defer logrus.SetLevel(logrus.InfoLevel)

pullOptions.Architecture = localArch
pullOptions.OS = localOS
pulledImages, err := runtime.Pull(ctx, withTag, config.PullPolicyMissing, pullOptions)
require.NoError(t, err, "pull busybox with same platform as before")
require.Len(t, pulledImages, 1)
require.NotContains(t, builder.String(), "local image may mistakenly specify wrong platform")
}()

// Repulling with a bogus architecture should yield an error and not
// choose the local image.
pullOptions.Architecture = "bogus"
Expand Down