2016-11-22 22:23:01 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2017-11-09 10:10:35 +00:00
|
|
|
"time"
|
|
|
|
|
2016-11-22 22:23:01 +00:00
|
|
|
"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.
|
2017-11-09 10:10:35 +00:00
|
|
|
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (resp *pb.PodSandboxStatusResponse, err error) {
|
|
|
|
const operation = "pod_sandbox_status"
|
|
|
|
defer func() {
|
|
|
|
recordOperation(operation, time.Now())
|
|
|
|
recordError(operation, err)
|
|
|
|
}()
|
|
|
|
|
2016-11-22 22:23:01 +00:00
|
|
|
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
|
|
|
|
|
|
|
rStatus := pb.PodSandboxState_SANDBOX_NOTREADY
|
|
|
|
if cState.Status == oci.ContainerStateRunning {
|
|
|
|
rStatus = pb.PodSandboxState_SANDBOX_READY
|
|
|
|
}
|
|
|
|
|
2018-02-13 10:45:31 +00:00
|
|
|
linux := &pb.LinuxPodSandboxStatus{
|
|
|
|
Namespaces: &pb.Namespace{
|
|
|
|
Options: &pb.NamespaceOption{
|
|
|
|
HostNetwork: sb.HostNetwork(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-07-19 19:03:22 +00:00
|
|
|
sandboxID := sb.ID()
|
2017-11-09 10:10:35 +00:00
|
|
|
resp = &pb.PodSandboxStatusResponse{
|
2016-11-22 22:23:01 +00:00
|
|
|
Status: &pb.PodSandboxStatus{
|
2017-08-04 11:13:19 +00:00
|
|
|
Id: sandboxID,
|
|
|
|
CreatedAt: podInfraContainer.CreatedAt().UnixNano(),
|
2017-08-29 22:57:26 +00:00
|
|
|
Network: &pb.PodSandboxNetworkStatus{Ip: sb.IP()},
|
2017-02-03 14:41:28 +00:00
|
|
|
State: rStatus,
|
2017-07-19 19:03:22 +00:00
|
|
|
Labels: sb.Labels(),
|
|
|
|
Annotations: sb.Annotations(),
|
|
|
|
Metadata: sb.Metadata(),
|
2018-02-13 10:45:31 +00:00
|
|
|
Linux: linux,
|
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
|
|
|
|
}
|