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 {
|
2017-02-03 14:41:28 +00:00
|
|
|
if result.Size != nil {
|
2017-11-09 10:10:35 +00:00
|
|
|
resp.Images = append(resp.Images, &pb.Image{
|
Return image references from the storage package
The image's canonical reference is a name with a digest of the image's
manifest, so in imageService.ImageStatus() and
imageService.ListImages(), divide the image's name list into tagged and
digested values, and if we have names, add canonical versions.
In Server.ContainerStatus(), return the image name as it was given to us
as the image, and the image digested reference as the image reference.
In Server.ListImages(), be sure to only return tagged names in the
RepoTags field. In Server.ImageStatus(), also return canonical
references in the RepoDigests field.
In Server.PullImage(), be sure that we consistently return the same
image reference for an image, whether we ended up pulling it or not.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-07-12 16:41:38 +00:00
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.RepoTags,
|
|
|
|
RepoDigests: result.RepoDigests,
|
|
|
|
Size_: *result.Size,
|
2017-02-03 14:41:28 +00:00
|
|
|
})
|
|
|
|
} else {
|
2017-11-09 10:10:35 +00:00
|
|
|
resp.Images = append(resp.Images, &pb.Image{
|
Return image references from the storage package
The image's canonical reference is a name with a digest of the image's
manifest, so in imageService.ImageStatus() and
imageService.ListImages(), divide the image's name list into tagged and
digested values, and if we have names, add canonical versions.
In Server.ContainerStatus(), return the image name as it was given to us
as the image, and the image digested reference as the image reference.
In Server.ListImages(), be sure to only return tagged names in the
RepoTags field. In Server.ImageStatus(), also return canonical
references in the RepoDigests field.
In Server.PullImage(), be sure that we consistently return the same
image reference for an image, whether we ended up pulling it or not.
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-07-12 16:41:38 +00:00
|
|
|
Id: result.ID,
|
|
|
|
RepoTags: result.RepoTags,
|
|
|
|
RepoDigests: result.RepoDigests,
|
2017-02-03 14:41:28 +00:00
|
|
|
})
|
|
|
|
}
|
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
|
|
|
}
|