2016-11-22 16:49:54 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-12-06 11:39:38 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/oci"
|
2016-11-22 16:49:54 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-02-03 14:41:28 +00:00
|
|
|
c, err := s.getContainerFromRequest(req.ContainerId)
|
2016-11-22 16:49:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:39:38 +00:00
|
|
|
if err := s.runtime.UpdateStatus(c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cStatus := s.runtime.ContainerStatus(c)
|
|
|
|
if cStatus.Status != oci.ContainerStateStopped {
|
2017-05-15 13:27:03 +00:00
|
|
|
if err := s.runtime.StopContainer(c, req.Timeout); err != nil {
|
2016-12-06 11:39:38 +00:00
|
|
|
return nil, fmt.Errorf("failed to stop container %s: %v", c.ID(), err)
|
|
|
|
}
|
2016-11-22 16:49:54 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 10:03:59 +00:00
|
|
|
s.containerStateToDisk(c)
|
|
|
|
|
2016-11-22 16:49:54 +00:00
|
|
|
resp := &pb.StopContainerResponse{}
|
|
|
|
logrus.Debugf("StopContainerResponse: %+v", resp)
|
|
|
|
return resp, nil
|
|
|
|
}
|