adjust status on container start failure

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-06-10 18:18:59 +02:00
parent 3f56193a15
commit 0b2f6b5354
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
4 changed files with 39 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/kubernetes-incubator/cri-o/oci"
"golang.org/x/net/context"
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
)
@ -15,12 +16,26 @@ func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerReque
if err != nil {
return nil, err
}
if err = s.runtime.StartContainer(c); err != nil {
return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err)
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)
}
s.containerStateToDisk(c)
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)
}()
err = s.runtime.StartContainer(c)
if err != nil {
return nil, fmt.Errorf("failed to start container %s: %v", c.ID(), err)
}
resp := &pb.StartContainerResponse{}
logrus.Debugf("StartContainerResponse %+v", resp)