2016-11-22 22:23:01 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kubernetes-incubator/cri-o/oci"
|
2017-08-05 11:40:46 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-11-22 22:23:01 +00:00
|
|
|
"golang.org/x/net/context"
|
2017-08-04 11:13:19 +00:00
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
2016-11-22 22:23:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PodSandboxStatus returns the Status of the PodSandbox.
|
|
|
|
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
|
|
|
|
logrus.Debugf("PodSandboxStatusRequest %+v", req)
|
2017-02-03 14:41:28 +00:00
|
|
|
sb, err := s.getPodSandboxFromRequest(req.PodSandboxId)
|
2016-11-22 22:23:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-07-19 19:03:22 +00:00
|
|
|
podInfraContainer := sb.InfraContainer()
|
2017-07-17 12:25:32 +00:00
|
|
|
cState := s.Runtime().ContainerStatus(podInfraContainer)
|
2016-11-22 22:23:01 +00:00
|
|
|
|
|
|
|
netNsPath, err := podInfraContainer.NetNsPath()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-07-19 19:03:22 +00:00
|
|
|
ip, err := s.netPlugin.GetContainerNetworkStatus(netNsPath, sb.Namespace(), sb.KubeName(), sb.ID())
|
2016-11-22 22:23:01 +00:00
|
|
|
if err != nil {
|
|
|
|
// ignore the error on network status
|
|
|
|
ip = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
rStatus := pb.PodSandboxState_SANDBOX_NOTREADY
|
|
|
|
if cState.Status == oci.ContainerStateRunning {
|
|
|
|
rStatus = pb.PodSandboxState_SANDBOX_READY
|
|
|
|
}
|
|
|
|
|
2017-07-19 19:03:22 +00:00
|
|
|
sandboxID := sb.ID()
|
2016-11-22 22:23:01 +00:00
|
|
|
resp := &pb.PodSandboxStatusResponse{
|
|
|
|
Status: &pb.PodSandboxStatus{
|
2017-08-04 11:13:19 +00:00
|
|
|
Id: sandboxID,
|
|
|
|
CreatedAt: podInfraContainer.CreatedAt().UnixNano(),
|
2017-02-03 14:41:28 +00:00
|
|
|
Network: &pb.PodSandboxNetworkStatus{Ip: ip},
|
|
|
|
State: rStatus,
|
2017-07-19 19:03:22 +00:00
|
|
|
Labels: sb.Labels(),
|
|
|
|
Annotations: sb.Annotations(),
|
|
|
|
Metadata: sb.Metadata(),
|
2016-11-22 22:23:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-06-09 11:04:31 +00:00
|
|
|
logrus.Debugf("PodSandboxStatusResponse: %+v", resp)
|
2016-11-22 22:23:01 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|