Server changes for supporting pod status
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
56df8bb639
commit
9cb0813d1e
2 changed files with 43 additions and 5 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mrunalp/ocid/utils"
|
"github.com/mrunalp/ocid/utils"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
@ -100,7 +101,7 @@ func (r *Runtime) UpdateStatus(c *Container) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus returns the state of a container.
|
// ContainerStatus returns the state of a container.
|
||||||
func (r *Runtime) ContainerStatus(c *Container) *specs.State {
|
func (r *Runtime) ContainerStatus(c *Container) *ContainerState {
|
||||||
return c.state
|
return c.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,11 +112,13 @@ type Container struct {
|
||||||
logPath string
|
logPath string
|
||||||
labels map[string]string
|
labels map[string]string
|
||||||
sandbox string
|
sandbox string
|
||||||
state *specs.State
|
state *ContainerState
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus represents the status of a container.
|
// ContainerStatus represents the status of a container.
|
||||||
type ContainerStatus struct {
|
type ContainerState struct {
|
||||||
|
specs.State
|
||||||
|
Created time.Time `json:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContainer creates a container object.
|
// NewContainer creates a container object.
|
||||||
|
|
|
@ -219,9 +219,44 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR
|
||||||
return &pb.RemovePodSandboxResponse{}, nil
|
return &pb.RemovePodSandboxResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func int64Ptr(i int64) *int64 {
|
||||||
|
return &i
|
||||||
|
}
|
||||||
|
|
||||||
|
func sPtr(s string) *string {
|
||||||
|
return &s
|
||||||
|
}
|
||||||
|
|
||||||
// PodSandboxStatus returns the Status of the PodSandbox.
|
// PodSandboxStatus returns the Status of the PodSandbox.
|
||||||
func (s *Server) PodSandboxStatus(context.Context, *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
|
func (s *Server) PodSandboxStatus(ctx context.Context, req *pb.PodSandboxStatusRequest) (*pb.PodSandboxStatusResponse, error) {
|
||||||
return nil, nil
|
sbName := req.PodSandboxId
|
||||||
|
if *sbName == "" {
|
||||||
|
return nil, fmt.Errorf("PodSandboxId should not be empty")
|
||||||
|
}
|
||||||
|
sb := s.state.sandboxes[*sbName]
|
||||||
|
if sb == nil {
|
||||||
|
return nil, fmt.Errorf("specified sandbox not found: %s", *sbName)
|
||||||
|
}
|
||||||
|
|
||||||
|
podInfraContainerName := *sbName + "-infra"
|
||||||
|
podInfraContainer := sb.containers[podInfraContainerName]
|
||||||
|
|
||||||
|
cState := s.runtime.ContainerStatus(podInfraContainer)
|
||||||
|
created := cState.Created.Unix()
|
||||||
|
|
||||||
|
netNsPath := fmt.Sprintf("/proc/%d/ns/net", cState.Pid)
|
||||||
|
|
||||||
|
return &pb.PodSandboxStatusResponse{
|
||||||
|
Status: &pb.PodSandboxStatus{
|
||||||
|
Id: sbName,
|
||||||
|
CreatedAt: int64Ptr(created),
|
||||||
|
Linux: &pb.LinuxPodSandboxStatus{
|
||||||
|
Namespaces: &pb.Namespace{
|
||||||
|
Network: sPtr(netNsPath),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListPodSandbox returns a list of SandBox.
|
// ListPodSandbox returns a list of SandBox.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue