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"
|
2017-11-09 10:10:35 +00:00
|
|
|
"time"
|
2016-10-18 14:48:33 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// RemoveImage removes the image.
|
2017-11-09 10:10:35 +00:00
|
|
|
func (s *Server) RemoveImage(ctx context.Context, req *pb.RemoveImageRequest) (resp *pb.RemoveImageResponse, err error) {
|
|
|
|
const operation = "remove_image"
|
|
|
|
defer func() {
|
|
|
|
recordOperation(operation, time.Now())
|
|
|
|
recordError(operation, err)
|
|
|
|
}()
|
|
|
|
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("RemoveImageRequest: %+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
|
|
|
var (
|
|
|
|
images []string
|
|
|
|
deleted bool
|
|
|
|
)
|
|
|
|
images, err = s.StorageImageServer().ResolveNames(image)
|
2016-10-18 14:48:33 +00:00
|
|
|
if err != nil {
|
2017-07-20 08:01:23 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, img := range images {
|
2017-11-11 10:55:55 +00:00
|
|
|
err = s.StorageImageServer().RemoveImage(s.ImageContext(), img)
|
2017-07-20 08:01:23 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Debugf("error deleting image %s: %v", img, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
deleted = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !deleted && err != nil {
|
2016-10-18 14:48:33 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2017-11-09 10:10:35 +00:00
|
|
|
resp = &pb.RemoveImageResponse{}
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("RemoveImageResponse: %+v", resp)
|
|
|
|
return resp, nil
|
2016-11-22 22:05:37 +00:00
|
|
|
}
|