mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
kubelet: Add image pulling event.
Since it takes a while (1-2mins) for kubelet to pulling a big image (>500MB). Just showing "Pending" for pod status is not very helpful. This commit introduces a "pulling" event, and inserts it before the kubelet starts to pull an image.
This commit is contained in:
parent
213e7a8ab6
commit
eb0fb43453
@ -105,9 +105,12 @@ type RuntimeHooks interface {
|
|||||||
// Determines whether the runtime should pull the specified container's image.
|
// Determines whether the runtime should pull the specified container's image.
|
||||||
ShouldPullImage(pod *api.Pod, container *api.Container, imagePresent bool) bool
|
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
|
// Runs after an image is pulled reporting its status. Error may be nil
|
||||||
// for a successful pull.
|
// 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.
|
// Pod is a group of containers, with the status of the pod.
|
||||||
|
@ -1330,20 +1330,21 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubeletTypes.Doc
|
|||||||
}
|
}
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if !ok {
|
if ok {
|
||||||
if err := dm.PullImage(spec, nil /* no pod secrets for the infra container */); err != nil {
|
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
dm.recorder.Eventf(ref, "failed", "Failed to pull image %q: %v", container.Image, err)
|
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
|
return "", err
|
||||||
}
|
}
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
dm.recorder.Eventf(ref, "pulled", "Successfully pulled Pod container image %q", container.Image)
|
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, "")
|
id, err := dm.runContainerInPod(pod, container, netNamespace, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1517,8 +1518,9 @@ func (dm *DockerManager) pullImage(pod *api.Pod, container *api.Container, pullS
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dm.runtimeHooks.ReportImagePulling(pod, container)
|
||||||
err = dm.PullImage(spec, pullSecrets)
|
err = dm.PullImage(spec, pullSecrets)
|
||||||
dm.runtimeHooks.ReportImagePull(pod, container, err)
|
dm.runtimeHooks.ReportImagePulled(pod, container, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func (kr *kubeletRuntimeHooks) ShouldPullImage(pod *api.Pod, container *api.Cont
|
|||||||
return false
|
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)
|
ref, err := kubecontainer.GenerateContainerRef(pod, container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Couldn't make a ref to pod %q, container %q: '%v'", pod.Name, container.Name, err)
|
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)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user