Bugfix: ctr container list can not get the proper status of container
Prior to this patch, when list containers by "ctr containers" or "ctr containers xxx", it will not get the proper status of conatinser(s). That was caused by the wrong implementation of State() for structure process, it only send a signal "0" to ping the "init" process and do nothing. Since the OCI/runc has implemented an interface Status(), we can use that. And I think this is more compatible with the design for containerd: - containerd -> runtime -> fun() Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
40d42a1aac
commit
ca7c504068
2 changed files with 21 additions and 2 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())
|
||||
|
|
|
@ -286,7 +286,22 @@ func (c *container) Stats() (*Stat, error) {
|
|||
|
||||
// Status implements the runtime Container interface.
|
||||
func (c *container) Status() (State, error) {
|
||||
return "running", nil
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue