2016-11-22 16:49:54 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ContainerStatus returns status of the container.
|
|
|
|
func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusRequest) (*pb.ContainerStatusResponse, error) {
|
|
|
|
logrus.Debugf("ContainerStatusRequest %+v", req)
|
2016-10-18 14:48:33 +00:00
|
|
|
s.Update()
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.runtime.UpdateStatus(c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
containerID := c.ID()
|
|
|
|
resp := &pb.ContainerStatusResponse{
|
|
|
|
Status: &pb.ContainerStatus{
|
2017-02-03 14:41:28 +00:00
|
|
|
Id: containerID,
|
2016-11-22 16:49:54 +00:00
|
|
|
Metadata: c.Metadata(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cState := s.runtime.ContainerStatus(c)
|
|
|
|
rStatus := pb.ContainerState_CONTAINER_UNKNOWN
|
|
|
|
|
|
|
|
switch cState.Status {
|
|
|
|
case oci.ContainerStateCreated:
|
|
|
|
rStatus = pb.ContainerState_CONTAINER_CREATED
|
|
|
|
created := cState.Created.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.CreatedAt = int64(created)
|
2016-11-22 16:49:54 +00:00
|
|
|
case oci.ContainerStateRunning:
|
|
|
|
rStatus = pb.ContainerState_CONTAINER_RUNNING
|
|
|
|
created := cState.Created.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.CreatedAt = int64(created)
|
2016-11-22 16:49:54 +00:00
|
|
|
started := cState.Started.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.StartedAt = int64(started)
|
2016-11-22 16:49:54 +00:00
|
|
|
case oci.ContainerStateStopped:
|
|
|
|
rStatus = pb.ContainerState_CONTAINER_EXITED
|
|
|
|
created := cState.Created.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.CreatedAt = int64(created)
|
2016-11-22 16:49:54 +00:00
|
|
|
started := cState.Started.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.StartedAt = int64(started)
|
2016-11-22 16:49:54 +00:00
|
|
|
finished := cState.Finished.UnixNano()
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.FinishedAt = int64(finished)
|
|
|
|
resp.Status.ExitCode = int32(cState.ExitCode)
|
2016-11-22 16:49:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 14:41:28 +00:00
|
|
|
resp.Status.State = rStatus
|
2016-11-22 16:49:54 +00:00
|
|
|
|
|
|
|
logrus.Debugf("ContainerStatusResponse: %+v", resp)
|
|
|
|
return resp, nil
|
|
|
|
}
|