continue remove image when can't find image id with ref

Signed-off-by: Crazykev <crazykev@zju.edu.cn>
This commit is contained in:
Crazykev 2017-05-15 14:11:19 +08:00
parent 885ddcc138
commit 1369a263f5
2 changed files with 9 additions and 3 deletions

View File

@ -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})

View File

@ -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
}