Top performs the equivalent of running `top` inside of container(s)
(ctx context.Context, client *containerd.Client, containers []string, opt types.ContainerTopOptions)
| 53 | |
| 54 | // Top performs the equivalent of running `top` inside of container(s) |
| 55 | func Top(ctx context.Context, client *containerd.Client, containers []string, opt types.ContainerTopOptions) error { |
| 56 | walker := &containerwalker.ContainerWalker{ |
| 57 | Client: client, |
| 58 | OnFound: func(ctx context.Context, found containerwalker.Found) error { |
| 59 | if found.MatchCount > 1 { |
| 60 | return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req) |
| 61 | } |
| 62 | return containerTop(ctx, opt.Stdout, client, found.Container.ID(), opt.PsArgs) |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | n, err := walker.Walk(ctx, containers[0]) |
| 67 | if err != nil { |
| 68 | return err |
| 69 | } else if n == 0 { |
| 70 | return fmt.Errorf("no such container %s", containers[0]) |
| 71 | } |
| 72 | return nil |
| 73 | } |
no test coverage detected