diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index c7d77e5567c..0d7106ac73a 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -105,9 +105,12 @@ type RuntimeHooks interface { // Determines whether the runtime should pull the specified container's image. ShouldPullImage(pod *api.Pod, container *api.Container, imagePresent bool) bool + // Runs when we start to pull an image. + ReportImagePulling(pod *api.Pod, container *api.Container) + // Runs after an image is pulled reporting its status. Error may be nil // for a successful pull. - ReportImagePull(pod *api.Pod, container *api.Container, err error) + ReportImagePulled(pod *api.Pod, container *api.Container, err error) } // Pod is a group of containers, with the status of the pod. diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index e16711184e0..98be36d7399 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -1330,20 +1330,21 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.Doc } return "", err } - if !ok { - if err := dm.PullImage(spec, nil /* no pod secrets for the infra container */); err != nil { - if ref != nil { - dm.recorder.Eventf(ref, "failed", "Failed to pull image %q: %v", container.Image, err) - } + if ok { + if ref != nil { + dm.recorder.Eventf(ref, "pulled", "Pod container image %q already present on machine", container.Image) + } + } else { + dm.runtimeHooks.ReportImagePulling(pod, container) + err := dm.PullImage(spec, nil /* no pod secrets for the infra container */) + dm.runtimeHooks.ReportImagePulled(pod, container, err) + if err != nil { return "", err } if ref != nil { dm.recorder.Eventf(ref, "pulled", "Successfully pulled Pod container image %q", container.Image) } } - if ok && ref != nil { - dm.recorder.Eventf(ref, "pulled", "Pod container image %q already present on machine", container.Image) - } id, err := dm.runContainerInPod(pod, container, netNamespace, "") if err != nil { @@ -1517,8 +1518,9 @@ func (dm *DockerManager) pullImage(pod *api.Pod, container *api.Container, pullS return nil } + dm.runtimeHooks.ReportImagePulling(pod, container) err = dm.PullImage(spec, pullSecrets) - dm.runtimeHooks.ReportImagePull(pod, container, err) + dm.runtimeHooks.ReportImagePulled(pod, container, err) return err } diff --git a/pkg/kubelet/runtime_hooks.go b/pkg/kubelet/runtime_hooks.go index ce36067bea2..4889364060c 100644 --- a/pkg/kubelet/runtime_hooks.go +++ b/pkg/kubelet/runtime_hooks.go @@ -49,7 +49,7 @@ func (kr *kubeletRuntimeHooks) ShouldPullImage(pod *api.Pod, container *api.Cont return false } -func (kr *kubeletRuntimeHooks) ReportImagePull(pod *api.Pod, container *api.Container, pullError error) { +func (kr *kubeletRuntimeHooks) ReportImagePulled(pod *api.Pod, container *api.Container, pullError error) { ref, err := kubecontainer.GenerateContainerRef(pod, container) if err != nil { glog.Errorf("Couldn't make a ref to pod %q, container %q: '%v'", pod.Name, container.Name, err) @@ -62,3 +62,12 @@ func (kr *kubeletRuntimeHooks) ReportImagePull(pod *api.Pod, container *api.Cont kr.recorder.Eventf(ref, "pulled", "Successfully pulled image %q", container.Image) } } + +func (kr *kubeletRuntimeHooks) ReportImagePulling(pod *api.Pod, container *api.Container) { + ref, err := kubecontainer.GenerateContainerRef(pod, container) + if err != nil { + glog.Errorf("Couldn't make a ref to pod %q, container %q: '%v'", pod.Name, container.Name, err) + return + } + kr.recorder.Eventf(ref, "pulling", "Pulling image %q for container: %v", container.Image, container.Name) +}