2016-11-22 22:05:37 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
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.
|
|
|
|
func (s *Server) ListImages(ctx context.Context, req *pb.ListImagesRequest) (*pb.ListImagesResponse, error) {
|
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
|
|
|
|
}
|
|
|
|
response := pb.ListImagesResponse{}
|
|
|
|
for _, result := range results {
|
2017-02-03 14:41:28 +00:00
|
|
|
if result.Size != nil {
|
|
|
|
response.Images = append(response.Images, &pb.Image{
|
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.Names,
|
|
|
|
Size_: *result.Size,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
response.Images = append(response.Images, &pb.Image{
|
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.Names,
|
|
|
|
})
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
logrus.Debugf("ListImagesResponse: %+v", response)
|
|
|
|
return &response, nil
|
2016-11-22 22:05:37 +00:00
|
|
|
}
|