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

[CRI] Continue remove image when can't find image id with ImageRef #45808

Merged
merged 1 commit into from
May 15, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/kubelet/dockershim/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ func (ds *dockerService) RemoveImage(image *runtimeapi.ImageSpec) error {
}
}
return nil
} else if err != nil && libdocker.IsImageNotFoundError(err) {
Copy link
Member

Choose a reason for hiding this comment

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

It should return err if error is not ImageNotFoundError and not nil.

Also should add a comment for the reason: dockerclient.InspectImageByID doesn't work with digest and repoTags, it is safe to continue removing it since there is another check below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@feiskyer THX~ Updated!

return nil
}
// dockerclient.InspectImageByID doesn't work with digest and repoTags,
// it is safe to continue removing it since there is another check below.
if err != nil && !libdocker.IsImageNotFoundError(err) {
return err
}

_, err = ds.client.RemoveImage(image.Image, dockertypes.ImageRemoveOptions{PruneChildren: true})
Expand Down
5 changes: 4 additions & 1 deletion pkg/kubelet/dockershim/libdocker/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,8 @@ func matchImageIDOnly(inspected dockertypes.ImageInspect, image string) bool {
// isImageNotFoundError returns whether the err is caused by image not found in docker
// TODO: Use native error tester once ImageNotFoundError is supported in docker-engine client(eg. ImageRemove())
func isImageNotFoundError(err error) bool {
return strings.Contains(err.Error(), "No such image:")
if err != nil {
return strings.Contains(err.Error(), "No such image:")
}
return false
}