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

Function topAction

cmd/nerdctl/compose/compose_top.go:47–101  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

45}
46
47func topAction(cmd *cobra.Command, args []string) error {
48 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
49 if err != nil {
50 return err
51 }
52
53 client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address)
54 if err != nil {
55 return err
56 }
57 defer cancel()
58 options, err := getComposeOptions(cmd, globalOptions.DebugFull, globalOptions.Experimental)
59 if err != nil {
60 return err
61 }
62 c, err := compose.New(client, globalOptions, options, cmd.OutOrStdout(), cmd.ErrOrStderr())
63 if err != nil {
64 return err
65 }
66 serviceNames, err := c.ServiceNames(args...)
67 if err != nil {
68 return err
69 }
70 containers, err := c.Containers(ctx, serviceNames...)
71 if err != nil {
72 return err
73 }
74 stdout := cmd.OutOrStdout()
75 for _, c := range containers {
76 cStatus, err := containerutil.ContainerStatus(ctx, c)
77 if err != nil {
78 return err
79 }
80 if cStatus.Status != containerd.Running {
81 continue
82 }
83
84 info, err := c.Info(ctx, containerd.WithoutRefreshedMetadata)
85 if err != nil {
86 return err
87 }
88 fmt.Fprintln(stdout, info.Labels[labels.Name])
89 // `compose ps` uses empty ps args
90 err = container.Top(ctx, client, []string{c.ID()}, types.ContainerTopOptions{
91 Stdout: cmd.OutOrStdout(),
92 GOptions: globalOptions,
93 })
94 if err != nil {
95 return err
96 }
97 fmt.Fprintln(stdout)
98 }
99
100 return nil
101}

Callers

nothing calls this directly

Calls 9

ProcessRootCmdFlagsFunction · 0.92
NewClientFunction · 0.92
NewFunction · 0.92
ContainerStatusFunction · 0.92
TopFunction · 0.92
getComposeOptionsFunction · 0.85
ServiceNamesMethod · 0.80
ContainersMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…