Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: use image reference during ContainerStatus #2096

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emmm, I think we could directly use imageID variable name here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user has changed Dockerfile and re-builds it with the same reference, the imageID will be changed. This is tricky part that we use reference to GetImage to make sure that ContainerStatus can be successfully executed after imageID was changed. That is why that we should use imageInfo.ID here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what you mean, what I want to say is should we use imageID := imageInfo.ID here to avoid the misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRI defines the imageRef in the protobuf. we just follow the rule here.

if len(imageInfo.RepoDigests) > 0 {
imageRef = imageInfo.RepoDigests[0]
}
Expand Down
11 changes: 8 additions & 3 deletions cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down