Skip to content

Commit

Permalink
Improve container top
Browse files Browse the repository at this point in the history
Check container state.
If container is not running then not call top api.
  • Loading branch information
skanehira committed Aug 25, 2019
1 parent febfce9 commit b1881e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/commands/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,16 @@ func (c *Container) Attach() (*exec.Cmd, error) {

// Top returns process information
func (c *Container) Top() (container.ContainerTopOKBody, error) {
detail, err := c.Inspect()
if err != nil {
return container.ContainerTopOKBody{}, err
}

// check container status
if !detail.State.Running {
return container.ContainerTopOKBody{}, errors.New("container is not running")
}

return c.Client.ContainerTop(context.Background(), c.ID, []string{})
}

Expand Down Expand Up @@ -411,7 +421,7 @@ func (c *Container) Inspect() (types.ContainerJSON, error) {

// RenderTop returns details about the container
func (c *Container) RenderTop() (string, error) {
result, err := c.Client.ContainerTop(context.Background(), c.ID, []string{})
result, err := c.Top()
if err != nil {
return "", err
}
Expand Down

0 comments on commit b1881e6

Please sign in to comment.