(cmd *cobra.Command, args []string)
| 49 | } |
| 50 | |
| 51 | func topAction(cmd *cobra.Command, args []string) error { |
| 52 | // NOTE: rootless container does not rely on cgroupv1. |
| 53 | // more details about possible ways to resolve this concern: #223 |
| 54 | globalOptions, err := helpers.ProcessRootCmdFlags(cmd) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | if rootlessutil.IsRootless() && infoutil.CgroupsVersion() == "1" { |
| 59 | return fmt.Errorf("top requires cgroup v2 for rootless containers, see https://rootlesscontaine.rs/getting-started/common/cgroup2/") |
| 60 | } |
| 61 | |
| 62 | if globalOptions.CgroupManager == "none" { |
| 63 | return errors.New("cgroup manager must not be \"none\"") |
| 64 | } |
| 65 | client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | defer cancel() |
| 70 | |
| 71 | containerID := args[0] |
| 72 | var psArgs string |
| 73 | if len(args) > 1 { |
| 74 | // Join all remaining arguments as ps args |
| 75 | psArgs = strings.Join(args[1:], " ") |
| 76 | } |
| 77 | |
| 78 | return container.Top(ctx, client, []string{containerID}, types.ContainerTopOptions{ |
| 79 | Stdout: cmd.OutOrStdout(), |
| 80 | GOptions: globalOptions, |
| 81 | PsArgs: psArgs, |
| 82 | }) |
| 83 | |
| 84 | } |
| 85 | |
| 86 | func topShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 87 | // show running container names |
nothing calls this directly
no test coverage detected
searching dependent graphs…