Skip to content

Commit

Permalink
continue remove image when can't find image id with ref
Browse files Browse the repository at this point in the history
Signed-off-by: Crazykev <crazykev@zju.edu.cn>
  • Loading branch information
Crazykev committed May 15, 2017
1 parent 885ddcc commit 1369a26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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) {
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
}

0 comments on commit 1369a26

Please sign in to comment.