Merge pull request #215 from HuKeping/runtime_status
Bugfix: ctr container list can not get the proper status of container
This commit is contained in:
commit
c44f03a1bf
5 changed files with 41 additions and 5 deletions
|
@ -146,7 +146,11 @@ func createAPIContainer(c runtime.Container, getPids bool) (*types.Container, er
|
|||
procs = append(procs, appendToProcs)
|
||||
}
|
||||
var pids []int
|
||||
state := c.State()
|
||||
state, err := c.Status()
|
||||
if err != nil {
|
||||
return nil, grpc.Errorf(codes.Internal, "get status for container: "+err.Error())
|
||||
}
|
||||
|
||||
if getPids && (state == runtime.Running || state == runtime.Paused) {
|
||||
if pids, err = c.Pids(); err != nil {
|
||||
return nil, grpc.Errorf(codes.Internal, "get all pids for container: "+err.Error())
|
||||
|
|
|
@ -52,6 +52,9 @@ type Container interface {
|
|||
OOM() (OOM, error)
|
||||
// UpdateResource updates the containers resources to new values
|
||||
UpdateResources(*Resource) error
|
||||
|
||||
// Status return the current status of the container.
|
||||
Status() (State, error)
|
||||
}
|
||||
|
||||
type OOM interface {
|
||||
|
|
|
@ -284,6 +284,26 @@ func (c *container) Stats() (*Stat, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Status implements the runtime Container interface.
|
||||
func (c *container) Status() (State, error) {
|
||||
args := c.runtimeArgs
|
||||
args = append(args, "state", c.id)
|
||||
|
||||
out, err := exec.Command(c.runtime, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(string(out))
|
||||
}
|
||||
|
||||
// We only require the runtime json output to have a top level Status field.
|
||||
var s struct {
|
||||
Status State `json:"status"`
|
||||
}
|
||||
if err := json.Unmarshal(out, &s); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s.Status, nil
|
||||
}
|
||||
|
||||
func (c *container) OOM() (OOM, error) {
|
||||
container, err := c.getLibctContainer()
|
||||
if err != nil {
|
||||
|
|
|
@ -61,6 +61,11 @@ func (c *container) Stats() (*Stat, error) {
|
|||
return nil, errors.New("Stats not yet implemented on Windows")
|
||||
}
|
||||
|
||||
// Status implements the runtime Container interface.
|
||||
func (c *container) Status() (State, error) {
|
||||
return "", errors.New("Status not yet implemented on Windows")
|
||||
}
|
||||
|
||||
func (c *container) OOM() (OOM, error) {
|
||||
return nil, errors.New("OOM not yet implemented on Windows")
|
||||
}
|
||||
|
|
|
@ -9,16 +9,20 @@ type GetContainersTask struct {
|
|||
}
|
||||
|
||||
func (s *Supervisor) getContainers(t *GetContainersTask) error {
|
||||
|
||||
if t.ID != "" {
|
||||
ci := s.containers[t.ID]
|
||||
if ci == nil {
|
||||
ci, ok := s.containers[t.ID]
|
||||
if !ok {
|
||||
return ErrContainerNotFound
|
||||
}
|
||||
t.Containers = append(t.Containers, ci.container)
|
||||
|
||||
return nil
|
||||
}
|
||||
for _, i := range s.containers {
|
||||
t.Containers = append(t.Containers, i.container)
|
||||
|
||||
for _, ci := range s.containers {
|
||||
t.Containers = append(t.Containers, ci.container)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue