mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Add default when latest not claimed
This commit is contained in:
parent
121c7046aa
commit
5552d7007c
@ -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
|
you must set a pull image policy of `Always` or specify a `:latest` tag on
|
||||||
your image.
|
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
|
## Using a Private Registry
|
||||||
|
|
||||||
Private registries may require keys to read images from them.
|
Private registries may require keys to read images from them.
|
||||||
|
@ -17,11 +17,10 @@ limitations under the License.
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
|
"k8s.io/kubernetes/pkg/util/parsers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func addDefaultingFuncs() {
|
func addDefaultingFuncs() {
|
||||||
@ -59,10 +58,10 @@ func addDefaultingFuncs() {
|
|||||||
},
|
},
|
||||||
func(obj *Container) {
|
func(obj *Container) {
|
||||||
if obj.ImagePullPolicy == "" {
|
if obj.ImagePullPolicy == "" {
|
||||||
// TODO(dchen1107): Move ParseImageName code to pkg/util
|
_, tag := parsers.ParseImageName(obj.Image)
|
||||||
parts := strings.Split(obj.Image, ":")
|
|
||||||
// Check image tag
|
// Check image tag
|
||||||
if parts[len(parts)-1] == "latest" {
|
|
||||||
|
if tag == "latest" {
|
||||||
obj.ImagePullPolicy = PullAlways
|
obj.ImagePullPolicy = PullAlways
|
||||||
} else {
|
} else {
|
||||||
obj.ImagePullPolicy = PullIfNotPresent
|
obj.ImagePullPolicy = PullIfNotPresent
|
||||||
|
@ -111,7 +111,7 @@ func TestReadPodsFromFile(t *testing.T) {
|
|||||||
Name: "image",
|
Name: "image",
|
||||||
Image: "test/image",
|
Image: "test/image",
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "Always",
|
||||||
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}},
|
SecurityContext: securitycontext.ValidSecurityContextWithContainerDefaults()}},
|
||||||
SecurityContext: &api.PodSecurityContext{},
|
SecurityContext: &api.PodSecurityContext{},
|
||||||
},
|
},
|
||||||
|
@ -199,7 +199,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Spec: api.PodSpec{
|
Spec: api.PodSpec{
|
||||||
NodeName: hostname,
|
NodeName: hostname,
|
||||||
Containers: []api.Container{{Name: "2", Image: "bar", ImagePullPolicy: ""}},
|
Containers: []api.Container{{Name: "2", Image: "bar:bartag", ImagePullPolicy: ""}},
|
||||||
SecurityContext: &api.PodSecurityContext{},
|
SecurityContext: &api.PodSecurityContext{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -247,7 +247,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
|
|||||||
|
|
||||||
Containers: []api.Container{{
|
Containers: []api.Container{{
|
||||||
Name: "2",
|
Name: "2",
|
||||||
Image: "bar",
|
Image: "bar:bartag",
|
||||||
TerminationMessagePath: "/dev/termination-log",
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
}},
|
}},
|
||||||
|
@ -132,12 +132,8 @@ func filterHTTPError(err error, image string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p dockerPuller) Pull(image string, secrets []api.Secret) 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 no tag was specified, use the default "latest".
|
||||||
if len(tag) == 0 {
|
repoToPull, tag := parsers.ParseImageName(image)
|
||||||
tag = "latest"
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := docker.PullImageOptions{
|
opts := docker.PullImageOptions{
|
||||||
Repository: repoToPull,
|
Repository: repoToPull,
|
||||||
|
Loading…
Reference in New Issue
Block a user