Skip to content

Commit d20b586

Browse files
committed
kube play: fix pull policy
Use the `newer` pull policy only for the "latest" tag and default to using `missing` otherwise. This speeds up `kube play` as it'll skip reaching out to the registry and also fixes other side-effects described in containers#19801. Fixes: containers#19801 Signed-off-by: Valentin Rothberg <[email protected]>
1 parent 16f6d6a commit d20b586

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

pkg/domain/infra/abi/play.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/containers/podman/v4/pkg/util"
3434
"github.com/containers/podman/v4/utils"
3535
"github.com/coreos/go-systemd/v22/daemon"
36+
"github.com/docker/distribution/reference"
3637
"github.com/opencontainers/go-digest"
3738
"github.com/opencontainers/selinux/go-selinux"
3839
"github.com/sirupsen/logrus"
@@ -992,12 +993,7 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
992993
}
993994
pulledImage = i
994995
} else {
995-
// NOTE: set the pull policy to "newer". This will cover cases
996-
// where the "latest" tag requires a pull and will also
997-
// transparently handle "localhost/" prefixed files which *may*
998-
// refer to a locally built image OR an image running a
999-
// registry on localhost.
1000-
pullPolicy := config.PullPolicyNewer
996+
pullPolicy := config.PullPolicyMissing
1001997
if len(container.ImagePullPolicy) > 0 {
1002998
// Make sure to lower the strings since K8s pull policy
1003999
// may be capitalized (see bugzilla.redhat.com/show_bug.cgi?id=1985905).
@@ -1006,6 +1002,14 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
10061002
if err != nil {
10071003
return nil, nil, err
10081004
}
1005+
} else {
1006+
if named, err := reference.ParseNamed(container.Image); err == nil {
1007+
tagged, isTagged := named.(reference.NamedTagged)
1008+
if isTagged && tagged.Tag() == "latest" {
1009+
// Make sure to always pull the latest image in case it got updated.
1010+
pullPolicy = config.PullPolicyNewer
1011+
}
1012+
}
10091013
}
10101014
// This ensures the image is the image store
10111015
pullOptions := &libimage.PullOptions{}

test/system/700-play.bats

+23
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,26 @@ EOF
764764
run_podman pod rm -a
765765
run_podman rm -a
766766
}
767+
768+
@test "podman kube play - pull policy" {
769+
skip_if_remote "pull debug logs only work locally"
770+
771+
yaml_source="$PODMAN_TMPDIR/test.yaml"
772+
_write_test_yaml command=true
773+
774+
# Exploit a debug message to make sure the expected pull policy is used
775+
run_podman --debug kube play $yaml_source
776+
assert "$output" =~ "Pulling image $IMAGE \(policy\: missing\)" "default pull policy is missing"
777+
run_podman kube down $yaml_source
778+
779+
local_image="localhost/name:latest"
780+
run_podman tag $IMAGE $local_image
781+
rm $yaml_source
782+
_write_test_yaml command=true image=$local_image
783+
784+
run_podman --debug kube play $yaml_source
785+
assert "$output" =~ "Pulling image $local_image \(policy\: newer\)" "pull policy is set to newhen pulling latest tag"
786+
run_podman kube down $yaml_source
787+
788+
run_podman rmi $local_image
789+
}

0 commit comments

Comments
 (0)