Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
fix agent crash when removing invalid image (#83)
Browse files Browse the repository at this point in the history
The client attempts to "noramlize" image refs when deleting to allow for
shortened image identifiers to be passed. When passing an invalid image
ref this could result in the client requesting deletion of a nil image
from the server. The server now silently succeed and do nothing while
the client now checks for passing a nil image ref and lets the user know
that no such image could be found.

Fixes #80

Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
  • Loading branch information
dweomer committed Oct 17, 2021
1 parent dfee5bb commit e597b95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/client/image/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package image
import (
"context"

"github.com/pkg/errors"
imagesv1 "github.com/rancher/kim/pkg/apis/services/images/v1alpha1"
"github.com/rancher/kim/pkg/client"
"github.com/sirupsen/logrus"
Expand All @@ -17,6 +18,9 @@ func (s *Remove) Do(ctx context.Context, k8s *client.Interface, image string) er
if err != nil {
return err
}
if ref == nil {
return errors.Errorf("image %q: not found", image)
}
res, err := imagesClient.Remove(ctx, &imagesv1.ImageRemoveRequest{Image: ref})
logrus.Debugf("%#v", res)
return err
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/images/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func (s *Server) Remove(ctx context.Context, req *imagesv1.ImageRemoveRequest) (
return nil, err
}
defer done(ctx)
if req.Image == nil {
return &imagesv1.ImageRemoveResponse{}, nil
}
img, err := s.Containerd.ImageService().Get(ctx, req.Image.Image)
if err != nil {
return nil, err
Expand Down

0 comments on commit e597b95

Please sign in to comment.