mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #2388 from dchen1107/image1
If the image with :latest tag specified in spec, pull even PullIfNotPresent is set.
This commit is contained in:
commit
e84ba3c184
@ -247,6 +247,16 @@ func (p dockerPuller) IsImagePresent(name string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// RequireLatestImage returns if the user wants the latest image
|
||||
func RequireLatestImage(name string) bool {
|
||||
_, tag := parseImageName(name)
|
||||
|
||||
if tag == "latest" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p throttledDockerPuller) IsImagePresent(name string) (bool, error) {
|
||||
return p.puller.IsImagePresent(name)
|
||||
}
|
||||
|
@ -714,11 +714,13 @@ func (kl *Kubelet) syncPod(pod *api.BoundPod, dockerContainers dockertools.Docke
|
||||
glog.V(3).Infof("Container with name %s--%s--%s doesn't exist, creating %#v", podFullName, uuid, container.Name, container)
|
||||
if !api.IsPullNever(container.ImagePullPolicy) {
|
||||
present, err := kl.dockerPuller.IsImagePresent(container.Image)
|
||||
latest := dockertools.RequireLatestImage(container.Image)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to inspect image: %s: %#v skipping pod %s container %s", container.Image, err, podFullName, container.Name)
|
||||
continue
|
||||
}
|
||||
if api.IsPullAlways(container.ImagePullPolicy) || !present {
|
||||
if api.IsPullAlways(container.ImagePullPolicy) ||
|
||||
(api.IsPullIfNotPresent(container.ImagePullPolicy) && (!present || latest)) {
|
||||
if err := kl.dockerPuller.Pull(container.Image); err != nil {
|
||||
glog.Errorf("Failed to pull image %s: %v skipping pod %s container %s.", container.Image, err, podFullName, container.Name)
|
||||
continue
|
||||
|
@ -1529,3 +1529,44 @@ func TestPurgeOldest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncPodsWithPullPolicy(t *testing.T) {
|
||||
kubelet, _, fakeDocker := newTestKubelet(t)
|
||||
puller := kubelet.dockerPuller.(*dockertools.FakeDockerPuller)
|
||||
puller.HasImages = []string{"existing_one", "want:latest"}
|
||||
kubelet.networkContainerImage = "custom_image_name"
|
||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
||||
err := kubelet.SyncPods([]api.BoundPod{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
Namespace: "new",
|
||||
Annotations: map[string]string{ConfigSourceAnnotationKey: "test"},
|
||||
},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{Name: "bar", Image: "pull_always_image", ImagePullPolicy: api.PullAlways},
|
||||
{Name: "bar1", Image: "pull_never_image", ImagePullPolicy: api.PullNever},
|
||||
{Name: "bar2", Image: "pull_if_not_present_image", ImagePullPolicy: api.PullIfNotPresent},
|
||||
{Name: "bar3", Image: "existing_one", ImagePullPolicy: api.PullIfNotPresent},
|
||||
{Name: "bar4", Image: "want:latest", ImagePullPolicy: api.PullIfNotPresent},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
kubelet.drainWorkers()
|
||||
|
||||
fakeDocker.Lock()
|
||||
|
||||
if !reflect.DeepEqual(puller.ImagesPulled, []string{"custom_image_name", "pull_always_image", "pull_if_not_present_image", "want:latest"}) {
|
||||
t.Errorf("Unexpected pulled containers: %v", puller.ImagesPulled)
|
||||
}
|
||||
|
||||
if len(fakeDocker.Created) != 6 {
|
||||
t.Errorf("Unexpected containers created %v", fakeDocker.Created)
|
||||
}
|
||||
fakeDocker.Unlock()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user