2016-11-22 22:05:37 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2017-11-09 10:10:35 +00:00
|
|
|
"time"
|
|
|
|
|
2017-08-05 11:40:46 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-11-22 22:05:37 +00:00
|
|
|
"golang.org/x/net/context"
|
2017-08-04 11:13:19 +00:00
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
2016-11-22 22:05:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ListImages lists existing images.
|
2017-11-09 10:10:35 +00:00
|
|
|
func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (resp *pb.ListImagesResponse, err error) {
|
|
|
|
const operation = "list_images"
|
|
|
|
defer func() {
|
|
|
|
recordOperation(operation, time.Now())
|
|
|
|
recordError(operation, err)
|
|
|
|
}()
|
|
|
|
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("ListImagesRequest: %+v", req)
|
|
|
|
filter := ""
|
|
|
|
reqFilter := req.GetFilter()
|
|
|
|
if reqFilter != nil {
|
|
|
|
filterImage := reqFilter.GetImage()
|
|
|
|
if filterImage != nil {
|
2017-02-03 14:41:28 +00:00
|
|
|
filter = filterImage.Image
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-31 15:48:10 +00:00
|
|
|
results, err := s.StorageImageServer().ListImages(s.ImageContext(), filter)
|
2016-10-18 14:48:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-09 10:10:35 +00:00
|
|
|
resp = &pb.ListImagesResponse{}
|
2016-10-18 14:48:33 +00:00
|
|
|
for _, result := range results {
|
2018-02-14 12:16:55 +00:00
|
|
|
resImg := &pb.Image{
|
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.RepoTags,
|
|
|
|
RepoDigests: result.RepoDigests,
|
|
|
|
}
|
|
|
|
uid, username := getUserFromImage(result.User)
|
|
|
|
if uid != nil {
|
|
|
|
resImg.Uid = &pb.Int64Value{Value: *uid}
|
|
|
|
}
|
|
|
|
resImg.Username = username
|
2017-02-03 14:41:28 +00:00
|
|
|
if result.Size != nil {
|
2018-02-14 12:16:55 +00:00
|
|
|
resImg.Size_ = *result.Size
|
2017-02-03 14:41:28 +00:00
|
|
|
}
|
2018-02-14 12:16:55 +00:00
|
|
|
resp.Images = append(resp.Images, resImg)
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
2017-11-09 10:10:35 +00:00
|
|
|
logrus.Debugf("ListImagesResponse: %+v", resp)
|
|
|
|
return resp, nil
|
2016-11-22 22:05:37 +00:00
|
|
|
}
|