diff --git a/docs/user-guide/images.md b/docs/user-guide/images.md index 92d04fb9f96..eddbba6d46a 100644 --- a/docs/user-guide/images.md +++ b/docs/user-guide/images.md @@ -60,6 +60,9 @@ pull an image if it already exists. If you would like to always force a pull you must set a pull image policy of `Always` or specify a `:latest` tag on your image. +If you did not specify tag of your image, it will be assumed as `:latest`, with +pull image policy of `Always` correspondingly. + ## Using a Private Registry Private registries may require keys to read images from them. diff --git a/pkg/api/v1/defaults.go b/pkg/api/v1/defaults.go index 68ce75bb951..88da9c442a6 100644 --- a/pkg/api/v1/defaults.go +++ b/pkg/api/v1/defaults.go @@ -17,11 +17,10 @@ limitations under the License. package v1 import ( - "strings" - "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util/intstr" + "k8s.io/kubernetes/pkg/util/parsers" ) func addDefaultingFuncs() { @@ -59,10 +58,10 @@ func addDefaultingFuncs() { }, func(obj *Container) { if obj.ImagePullPolicy == "" { - // TODO(dchen1107): Move ParseImageName code to pkg/util - parts := strings.Split(obj.Image, ":") + _, tag := parsers.ParseImageName(obj.Image) // Check image tag - if parts[len(parts)-1] == "latest" { + + if tag == "latest" { obj.ImagePullPolicy = PullAlways } else { obj.ImagePullPolicy = PullIfNotPresent diff --git a/pkg/kubelet/config/file_test.go b/pkg/kubelet/config/file_test.go index 0f2e9ea9ec5..be30c035a88 100644 --- a/pkg/kubelet/config/file_test.go +++ b/pkg/kubelet/config/file_test.go @@ -111,7 +111,7 @@ func TestReadPodsFromFile(t *testing.T) { Name: "image", Image: "test/image", TerminationMessagePath: "/dev/termination-log", - ImagePullPolicy: "IfNotPresent", + ImagePullPolicy: "Always", SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}}, SecurityContext: &api.PodSecurityContext{}, }, diff --git a/pkg/kubelet/config/http_test.go b/pkg/kubelet/config/http_test.go index f257bc3fc68..7a40140c127 100644 --- a/pkg/kubelet/config/http_test.go +++ b/pkg/kubelet/config/http_test.go @@ -199,7 +199,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { }, Spec: api.PodSpec{ NodeName: hostname, - Containers: []api.Container{{Name: "2", Image: "bar", ImagePullPolicy: ""}}, + Containers: []api.Container{{Name: "2", Image: "bar:bartag", ImagePullPolicy: ""}}, SecurityContext: &api.PodSecurityContext{}, }, }, @@ -247,7 +247,7 @@ func TestExtractPodsFromHTTP(t *testing.T) { Containers: []api.Container{{ Name: "2", - Image: "bar", + Image: "bar:bartag", TerminationMessagePath: "/dev/termination-log", ImagePullPolicy: "IfNotPresent", }}, diff --git a/pkg/kubelet/dockertools/docker.go b/pkg/kubelet/dockertools/docker.go index 640742e1842..96235ef2a3f 100644 --- a/pkg/kubelet/dockertools/docker.go +++ b/pkg/kubelet/dockertools/docker.go @@ -132,12 +132,8 @@ func filterHTTPError(err error, image string) error { } func (p dockerPuller) Pull(image string, secrets []api.Secret) error { - repoToPull, tag := parsers.ParseImageName(image) - // If no tag was specified, use the default "latest". - if len(tag) == 0 { - tag = "latest" - } + repoToPull, tag := parsers.ParseImageName(image) opts := docker.PullImageOptions{ Repository: repoToPull,