Commit e1196319 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #45808 from Crazykev/quick-fix

Automatic merge from submit-queue (batch tested with PRs 45171, 43947, 45788, 45822, 45808) [CRI] Continue remove image when can't find image id with ImageRef Signed-off-by: 's avatarCrazykev <crazykev@zju.edu.cn> **What this PR does / why we need it**: Should try to remove imageRef as repo:tag when can't find it as imageID. /cc @feiskyer @Random-Liu PTAL also /cc @xlgao-zju @heartlock **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note None ```
parents c57c9525 1369a263
......@@ -101,8 +101,11 @@ func (ds *dockerService) RemoveImage(image *runtimeapi.ImageSpec) error {
}
}
return nil
} else if err != nil && libdocker.IsImageNotFoundError(err) {
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})
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment