Skip to content

Commit 268aae8

Browse files
authored
Merge pull request #4063 from coderbirju/update-containr-top
fix: Pass ps_args as option to container top
2 parents 83d5173 + 710dfce commit 268aae8

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

cmd/nerdctl/container/container_top.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package container
1919
import (
2020
"errors"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/spf13/cobra"
2425

@@ -66,9 +67,18 @@ func topAction(cmd *cobra.Command, args []string) error {
6667
return err
6768
}
6869
defer cancel()
69-
return container.Top(ctx, client, args, types.ContainerTopOptions{
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{
7079
Stdout: cmd.OutOrStdout(),
7180
GOptions: globalOptions,
81+
PsArgs: psArgs,
7282
})
7383

7484
}

pkg/api/types/container_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ type ContainerTopOptions struct {
343343
Stdout io.Writer
344344
// GOptions is the global options
345345
GOptions GlobalCommandOptions
346+
347+
// Arguments to pass through to the ps command
348+
PsArgs string
346349
}
347350

348351
// ContainerInspectOptions specifies options for `nerdctl container inspect`

pkg/cmd/container/top.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ package container
2828
import (
2929
"context"
3030
"fmt"
31-
"strings"
3231

3332
containerd "github.com/containerd/containerd/v2/client"
3433

@@ -60,7 +59,7 @@ func Top(ctx context.Context, client *containerd.Client, containers []string, op
6059
if found.MatchCount > 1 {
6160
return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
6261
}
63-
return containerTop(ctx, opt.Stdout, client, found.Container.ID(), strings.Join(containers[1:], " "))
62+
return containerTop(ctx, opt.Stdout, client, found.Container.ID(), opt.PsArgs)
6463
},
6564
}
6665

0 commit comments

Comments
 (0)