Merge pull request #111772 from pacoxu/image-pull-time

kubelet: make the image pull time more accurate in event
This commit is contained in:
Kubernetes Prow Robot 2022-11-07 14:52:16 -08:00 committed by GitHub
commit 43a2bb4df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -164,8 +164,7 @@ func (m *imageManager) EnsureImageExists(ctx context.Context, pod *v1.Pod, conta
return "", imagePullResult.err.Error(), ErrImagePull
}
m.podPullingTimeRecorder.RecordImageFinishedPulling(pod.UID)
m.logIt(ref, v1.EventTypeNormal, events.PulledImage, logPrefix, fmt.Sprintf("Successfully pulled image %q in %v", container.Image, time.Since(startTime)), klog.Info)
m.logIt(ref, v1.EventTypeNormal, events.PulledImage, logPrefix, fmt.Sprintf("Successfully pulled image %q in %v (%v including waiting)", container.Image, imagePullResult.pullDuration, time.Since(startTime)), klog.Info)
m.backOff.GC()
return imagePullResult.imageRef, "", nil
}

View File

@ -27,8 +27,9 @@ import (
)
type pullResult struct {
imageRef string
err error
imageRef string
err error
pullDuration time.Duration
}
type imagePuller interface {
@ -47,10 +48,12 @@ func newParallelImagePuller(imageService kubecontainer.ImageService) imagePuller
func (pip *parallelImagePuller) pullImage(ctx context.Context, spec kubecontainer.ImageSpec, pullSecrets []v1.Secret, pullChan chan<- pullResult, podSandboxConfig *runtimeapi.PodSandboxConfig) {
go func() {
startTime := time.Now()
imageRef, err := pip.imageService.PullImage(ctx, spec, pullSecrets, podSandboxConfig)
pullChan <- pullResult{
imageRef: imageRef,
err: err,
imageRef: imageRef,
err: err,
pullDuration: time.Since(startTime),
}
}()
}
@ -89,10 +92,12 @@ func (sip *serialImagePuller) pullImage(ctx context.Context, spec kubecontainer.
func (sip *serialImagePuller) processImagePullRequests() {
for pullRequest := range sip.pullRequests {
startTime := time.Now()
imageRef, err := sip.imageService.PullImage(pullRequest.ctx, pullRequest.spec, pullRequest.pullSecrets, pullRequest.podSandboxConfig)
pullRequest.pullChan <- pullResult{
imageRef: imageRef,
err: err,
imageRef: imageRef,
err: err,
pullDuration: time.Since(startTime),
}
}
}