2016-11-22 17:49:54 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-12-06 12:39:38 +01:00
|
|
|
"github.com/kubernetes-incubator/cri-o/oci"
|
2017-08-05 07:40:46 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-11-22 17:49:54 +01:00
|
|
|
"golang.org/x/net/context"
|
2017-08-04 13:13:19 +02:00
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
2016-11-22 17:49:54 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// StopContainer stops a running container with a grace period (i.e., timeout).
|
|
|
|
func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) {
|
|
|
|
logrus.Debugf("StopContainerRequest %+v", req)
|
2017-07-31 19:23:20 -04:00
|
|
|
c, err := s.GetContainerFromRequest(req.ContainerId)
|
2016-11-22 17:49:54 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-07-17 08:25:32 -04:00
|
|
|
cStatus := s.Runtime().ContainerStatus(c)
|
2016-12-06 12:39:38 +01:00
|
|
|
if cStatus.Status != oci.ContainerStateStopped {
|
2017-07-17 08:25:32 -04:00
|
|
|
if err := s.Runtime().StopContainer(c, req.Timeout); err != nil {
|
2016-12-06 12:39:38 +01:00
|
|
|
return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err)
|
|
|
|
}
|
2017-07-31 14:38:45 -04:00
|
|
|
if err := s.StorageRuntimeServer().StopContainer(c.ID()); err != nil {
|
2017-05-21 15:47:01 +02:00
|
|
|
return nil, fmt.Errorf("failed to unmount container %s: %v", c.ID(), err)
|
|
|
|
}
|
2016-11-22 17:49:54 +01:00
|
|
|
}
|
|
|
|
|
2017-07-20 13:05:12 -04:00
|
|
|
s.ContainerStateToDisk(c)
|
2017-05-11 12:03:59 +02:00
|
|
|
|
2016-11-22 17:49:54 +01:00
|
|
|
resp := &pb.StopContainerResponse{}
|
2017-08-17 14:27:29 -07:00
|
|
|
logrus.Debugf("StopContainerResponse %s: %+v", c.ID(), resp)
|
2016-11-22 17:49:54 +01:00
|
|
|
return resp, nil
|
|
|
|
}
|