From 4ab58928acb6adfb85ff1355b096ac586198219b Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Tue, 14 Aug 2018 19:50:49 +0800 Subject: [PATCH] bugfix: use image reference during ContainerStatus If user repush image with the same reference, the image ID will be changed. For now, pouch daemon will remove the old image ID so that CRI fails to fetch the running container. Before upgrade pouch daemon image manager, we use reference to get image instead of id. Signed-off-by: Wei Fu --- cri/v1alpha1/cri.go | 11 ++++++++--- cri/v1alpha2/cri.go | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cri/v1alpha1/cri.go b/cri/v1alpha1/cri.go index 477ce659a..7a3ac910a 100644 --- a/cri/v1alpha1/cri.go +++ b/cri/v1alpha1/cri.go @@ -710,11 +710,16 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt labels, annotations := extractLabels(container.Config.Labels) - imageRef := container.Image - imageInfo, err := c.ImageMgr.GetImage(ctx, imageRef) + // FIXME(fuwei): if user repush image with the same reference, the image + // ID will be changed. For now, pouch daemon will remove the old image ID + // so that CRI fails to fetch the running container. Before upgrade + // pouch daemon image manager, we use reference to get image instead of + // id. + imageInfo, err := c.ImageMgr.GetImage(ctx, container.Config.Image) if err != nil { - return nil, fmt.Errorf("failed to get image %s: %v", imageRef, err) + return nil, fmt.Errorf("failed to get image %s: %v", container.Config.Image, err) } + imageRef := imageInfo.ID if len(imageInfo.RepoDigests) > 0 { imageRef = imageInfo.RepoDigests[0] } diff --git a/cri/v1alpha2/cri.go b/cri/v1alpha2/cri.go index ab46b7db3..5fedaa50c 100644 --- a/cri/v1alpha2/cri.go +++ b/cri/v1alpha2/cri.go @@ -709,11 +709,16 @@ func (c *CriManager) ContainerStatus(ctx context.Context, r *runtime.ContainerSt labels, annotations := extractLabels(container.Config.Labels) - imageRef := container.Image - imageInfo, err := c.ImageMgr.GetImage(ctx, imageRef) + // FIXME(fuwei): if user repush image with the same reference, the image + // ID will be changed. For now, pouch daemon will remove the old image ID + // so that CRI fails to fetch the running container. Before upgrade + // pouch daemon image manager, we use reference to get image instead of + // id. + imageInfo, err := c.ImageMgr.GetImage(ctx, container.Config.Image) if err != nil { - return nil, fmt.Errorf("failed to get image %s: %v", imageRef, err) + return nil, fmt.Errorf("failed to get image %s: %v", container.Config.Image, err) } + imageRef := imageInfo.ID if len(imageInfo.RepoDigests) > 0 { imageRef = imageInfo.RepoDigests[0] }