2016-11-22 16:49:54 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2017-06-10 16:18:59 +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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StartContainer starts the container.
|
|
|
|
func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerRequest) (*pb.StartContainerResponse, error) {
|
|
|
|
logrus.Debugf("StartContainerRequest %+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
|
|
|
|
}
|
2017-06-10 16:18:59 +00:00
|
|
|
state := s.runtime.ContainerStatus(c)
|
|
|
|
if state.Status != oci.ContainerStateCreated {
|
|
|
|
return nil, fmt.Errorf("container %s is not in created state: %s", c.ID(), state.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
// if the call to StartContainer fails below we still want to fill
|
|
|
|
// some fields of a container status. In particular, we're going to
|
|
|
|
// adjust container started/finished time and set an error to be
|
|
|
|
// returned in the Reason field for container status call.
|
|
|
|
if err != nil {
|
|
|
|
s.runtime.SetStartFailed(c, err)
|
|
|
|
}
|
|
|
|
s.containerStateToDisk(c)
|
|
|
|
}()
|
2016-11-22 16:49:54 +00:00
|
|
|
|
2017-06-10 16:18:59 +00:00
|
|
|
err = s.runtime.StartContainer(c)
|
|
|
|
if err != nil {
|
2016-11-22 16:49:54 +00:00
|
|
|
return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &pb.StartContainerResponse{}
|
|
|
|
logrus.Debugf("StartContainerResponse %+v", resp)
|
|
|
|
return resp, nil
|
|
|
|
}
|