2016-11-22 22:05:37 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2016-10-18 14:48:33 +00:00
|
|
|
"fmt"
|
2017-07-20 08:01:23 +00:00
|
|
|
"strings"
|
2016-10-18 14:48:33 +00:00
|
|
|
|
2017-05-17 17:18:35 +00:00
|
|
|
"github.com/containers/storage"
|
2017-08-02 15:17:45 +00:00
|
|
|
"github.com/pkg/errors"
|
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"
|
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ImageStatus returns the status of the image.
|
|
|
|
func (s *Server) ImageStatus(ctx context.Context, req *pb.ImageStatusRequest) (*pb.ImageStatusResponse, error) {
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("ImageStatusRequest: %+v", req)
|
|
|
|
image := ""
|
|
|
|
img := req.GetImage()
|
|
|
|
if img != nil {
|
2017-02-03 14:41:28 +00:00
|
|
|
image = img.Image
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
if image == "" {
|
|
|
|
return nil, fmt.Errorf("no image specified")
|
|
|
|
}
|
2017-07-20 08:01:23 +00:00
|
|
|
images, err := s.StorageImageServer().ResolveNames(image)
|
|
|
|
if err != nil {
|
|
|
|
// This means we got an image ID
|
|
|
|
if strings.Contains(err.Error(), "cannot specify 64-byte hexadecimal strings") {
|
|
|
|
images = append(images, image)
|
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// match just the first registry as that's what kube meant
|
|
|
|
image = images[0]
|
2017-07-17 12:25:32 +00:00
|
|
|
status, err := s.StorageImageServer().ImageStatus(s.ImageContext(), image)
|
2016-10-18 14:48:33 +00:00
|
|
|
if err != nil {
|
2017-08-02 15:17:45 +00:00
|
|
|
if errors.Cause(err) == storage.ErrImageUnknown {
|
2016-12-21 20:54:15 +00:00
|
|
|
return &pb.ImageStatusResponse{}, nil
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp := &pb.ImageStatusResponse{
|
|
|
|
Image: &pb.Image{
|
2017-02-03 14:41:28 +00:00
|
|
|
Id: status.ID,
|
2016-10-18 14:48:33 +00:00
|
|
|
RepoTags: status.Names,
|
2017-02-03 14:41:28 +00:00
|
|
|
Size_: *status.Size,
|
2017-05-20 15:08:00 +00:00
|
|
|
// TODO: https://github.com/kubernetes-incubator/cri-o/issues/531
|
2016-10-18 14:48:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
logrus.Debugf("ImageStatusResponse: %+v", resp)
|
|
|
|
return resp, nil
|
2016-11-22 22:05:37 +00:00
|
|
|
}
|