Skip to content

Commit

Permalink
bugfix: distinguish NotFound error with others about image
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Aug 22, 2018
1 parent d6a4571 commit 400e7dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
7 changes: 2 additions & 5 deletions cri/v1alpha1/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,7 @@ func (c *CriManager) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ

imageInfo, err := c.ImageMgr.GetImage(ctx, ref.String())
if err != nil {
// TODO: separate ErrImageNotFound with others.
// Now we just return empty if the error occurred.
return &runtime.ImageStatusResponse{}, nil
return nil, err
}

image, err := imageToCriImage(imageInfo)
Expand Down Expand Up @@ -1046,8 +1044,7 @@ func (c *CriManager) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequ

if err := c.ImageMgr.RemoveImage(ctx, imageRef, false); err != nil {
if errtypes.IsNotfound(err) {
// TODO: separate ErrImageNotFound with others.
// Now we just return empty if the error occurred.
// Now we just return empty if the ErrorNotFound occurred.
return &runtime.RemoveImageResponse{}, nil
}
return nil, err
Expand Down
13 changes: 8 additions & 5 deletions cri/v1alpha1/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/utils"

"github.com/alibaba/pouch/pkg/errtypes"
"github.com/containerd/cgroups"
containerdmount "github.com/containerd/containerd/mount"
"github.com/containerd/typeurl"
Expand Down Expand Up @@ -822,17 +823,19 @@ func imageToCriImage(image *apitypes.ImageInfo) (*runtime.Image, error) {
// ensureSandboxImageExists pulls the image when it's not present.
func (c *CriManager) ensureSandboxImageExists(ctx context.Context, imageRef string) error {
_, _, _, err := c.ImageMgr.CheckReference(ctx, imageRef)
// TODO: maybe we should distinguish NotFound error with others.
if err == nil {
return nil
}

err = c.ImageMgr.PullImage(ctx, imageRef, nil, bytes.NewBuffer([]byte{}))
if err != nil {
return fmt.Errorf("pull sandbox image %q failed: %v", imageRef, err)
if errtypes.IsNotfound(err) {
err = c.ImageMgr.PullImage(ctx, imageRef, nil, bytes.NewBuffer([]byte{}))
if err != nil {
return fmt.Errorf("failed to pull sandbox image %q: %v", imageRef, err)
}
return nil
}

return nil
return fmt.Errorf("failed to checkReference sandbox image %q: %v", imageRef, err)
}

// getUserFromImageUser gets uid or user name of the image user.
Expand Down
7 changes: 2 additions & 5 deletions cri/v1alpha2/cri.go
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,7 @@ func (c *CriManager) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequ

imageInfo, err := c.ImageMgr.GetImage(ctx, ref.String())
if err != nil {
// TODO: separate ErrImageNotFound with others.
// Now we just return empty if the error occurred.
return &runtime.ImageStatusResponse{}, nil
return nil, err
}

image, err := imageToCriImage(imageInfo)
Expand Down Expand Up @@ -1069,8 +1067,7 @@ func (c *CriManager) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequ

if err := c.ImageMgr.RemoveImage(ctx, imageRef, false); err != nil {
if errtypes.IsNotfound(err) {
// TODO: separate ErrImageNotFound with others.
// Now we just return empty if the error occurred.
// Now we just return empty if the ErrorNotFound occurred.
return &runtime.RemoveImageResponse{}, nil
}
return nil, err
Expand Down
14 changes: 8 additions & 6 deletions cri/v1alpha2/cri_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/alibaba/pouch/daemon/mgr"
"github.com/alibaba/pouch/pkg/utils"

"github.com/alibaba/pouch/pkg/errtypes"
"github.com/containerd/cgroups"
"github.com/containerd/typeurl"
"github.com/cri-o/ocicni/pkg/ocicni"
Expand Down Expand Up @@ -822,17 +823,18 @@ func imageToCriImage(image *apitypes.ImageInfo) (*runtime.Image, error) {
// ensureSandboxImageExists pulls the image when it's not present.
func (c *CriManager) ensureSandboxImageExists(ctx context.Context, imageRef string) error {
_, _, _, err := c.ImageMgr.CheckReference(ctx, imageRef)
// TODO: maybe we should distinguish NotFound error with others.
if err == nil {
return nil
}

err = c.ImageMgr.PullImage(ctx, imageRef, nil, bytes.NewBuffer([]byte{}))
if err != nil {
return fmt.Errorf("pull sandbox image %q failed: %v", imageRef, err)
if errtypes.IsNotfound(err) {
err = c.ImageMgr.PullImage(ctx, imageRef, nil, bytes.NewBuffer([]byte{}))
if err != nil {
return fmt.Errorf("failed to pull sandbox image %q: %v", imageRef, err)
}
return nil
}

return nil
return fmt.Errorf("failed to checkReference sandbox image %q: %v", imageRef, err)
}

// getUserFromImageUser gets uid or user name of the image user.
Expand Down

0 comments on commit 400e7dd

Please sign in to comment.