MCPcopy Create free account
hub / github.com/containerd/nerdctl / topAction

Function topAction

cmd/nerdctl/container/container_top.go:51–84  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

49}
50
51func 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
86func topShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
87 // show running container names

Callers

nothing calls this directly

Calls 5

ProcessRootCmdFlagsFunction · 0.92
IsRootlessFunction · 0.92
CgroupsVersionFunction · 0.92
NewClientFunction · 0.92
TopFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…