-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve crictl inspect[pi]
commands to allow filtering
#1553
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,19 +218,71 @@ var podStatusCommand = &cli.Command{ | |
Name: "template", | ||
Usage: "The template string is only used when output is go-template; The Template format is golang template", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "name", | ||
Usage: "Filter by pod name regular expression pattern", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "namespace", | ||
Usage: "Filter by pod namespace regular expression pattern", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "state", | ||
Aliases: []string{"s"}, | ||
Usage: "Filter by pod state", | ||
}, | ||
&cli.StringSliceFlag{ | ||
Name: "label", | ||
Usage: "Filter by key=value label", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "latest", | ||
Aliases: []string{"l"}, | ||
Usage: "Show the most recently created pod", | ||
}, | ||
&cli.IntFlag{ | ||
Name: "last", | ||
Aliases: []string{"n"}, | ||
Usage: "Show last n recently created pods. Set 0 for unlimited", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
if c.NArg() == 0 { | ||
return cli.ShowSubcommandHelp(c) | ||
} | ||
runtimeClient, err := getRuntimeService(c, 0) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ids := c.Args().Slice() | ||
|
||
if len(ids) == 0 { | ||
opts := &listOptions{ | ||
nameRegexp: c.String("name"), | ||
podNamespaceRegexp: c.String("namespace"), | ||
state: c.String("state"), | ||
latest: c.Bool("latest"), | ||
last: c.Int("last"), | ||
} | ||
opts.labels, err = parseLabelStringSlice(c.StringSlice("label")) | ||
if err != nil { | ||
return fmt.Errorf("parse label string slice: %w", err) | ||
} | ||
sbs, err := ListPodSandboxes(runtimeClient, opts) | ||
if err != nil { | ||
return fmt.Errorf("listing pod sandboxes: %w", err) | ||
} | ||
for _, sb := range sbs { | ||
ids = append(ids, sb.GetId()) | ||
} | ||
} | ||
|
||
if len(ids) == 0 { | ||
logrus.Error("No IDs provided or nothing found per filter") | ||
return cli.ShowSubcommandHelp(c) | ||
} | ||
|
||
if err := podSandboxStatus( | ||
runtimeClient, | ||
c.Args().Slice(), | ||
ids, | ||
c.String("output"), | ||
c.Bool("quiet"), | ||
c.String("template"), | ||
|
@@ -253,30 +305,30 @@ var listPodCommand = &cli.Command{ | |
}, | ||
&cli.StringFlag{ | ||
Name: "name", | ||
Usage: "filter by pod name regular expression pattern", | ||
Usage: "Filter by pod name regular expression pattern", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "namespace", | ||
Usage: "filter by pod namespace regular expression pattern", | ||
Usage: "Filter by pod namespace regular expression pattern", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "state", | ||
Aliases: []string{"s"}, | ||
Usage: "filter by pod state", | ||
Usage: "Filter by pod state", | ||
}, | ||
&cli.StringSliceFlag{ | ||
Name: "label", | ||
Usage: "filter by key=value label", | ||
Usage: "Filter by key=value label", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "verbose", | ||
Aliases: []string{"v"}, | ||
Usage: "show verbose info for pods", | ||
Usage: "Show verbose info for pods", | ||
}, | ||
&cli.BoolFlag{ | ||
Name: "quiet", | ||
Aliases: []string{"q"}, | ||
Usage: "list only pod IDs", | ||
Usage: "List only pod IDs", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "output", | ||
|
@@ -322,7 +374,7 @@ var listPodCommand = &cli.Command{ | |
if err != nil { | ||
return err | ||
} | ||
if err = ListPodSandboxes(runtimeClient, opts); err != nil { | ||
if err = OutputPodSandboxes(runtimeClient, opts); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if filtered by reference, what image reference will the output use as a main one? My understanding is that even with the filter, the output may show different reference as a "main" name of an image and tag one filtered by in a list of alternative names. Is it right? I wonder this is actually the case and whether we can either improve output or make it clear in docs so not to confuse users There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, pods are not filterable by reference, are we speaking about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case of various filters, potential improvement over time may be to show filter-specific additional column. For since it may be time passed since that value in the filter, for example. This is just a nit. |
||
return fmt.Errorf("listing pod sandboxes: %w", err) | ||
} | ||
return nil | ||
|
@@ -482,7 +534,7 @@ func outputPodSandboxStatusTable(r *pb.PodSandboxStatusResponse, verbose bool) { | |
|
||
// ListPodSandboxes sends a ListPodSandboxRequest to the server, and parses | ||
// the returned ListPodSandboxResponse. | ||
func ListPodSandboxes(client internalapi.RuntimeService, opts *listOptions) error { | ||
func ListPodSandboxes(client internalapi.RuntimeService, opts *listOptions) ([]*pb.PodSandbox, error) { | ||
filter := &pb.PodSandboxFilter{} | ||
if opts.id != "" { | ||
filter.Id = opts.id | ||
|
@@ -513,9 +565,18 @@ func ListPodSandboxes(client internalapi.RuntimeService, opts *listOptions) erro | |
}) | ||
logrus.Debugf("ListPodSandboxResponse: %v", r) | ||
if err != nil { | ||
return err | ||
return nil, fmt.Errorf("call list sandboxes RPC: %w", err) | ||
} | ||
return getSandboxesList(r, opts), nil | ||
} | ||
|
||
// OutputPodSandboxes sends a ListPodSandboxRequest to the server, and parses | ||
// the returned ListPodSandboxResponse for output. | ||
func OutputPodSandboxes(client internalapi.RuntimeService, opts *listOptions) error { | ||
r, err := ListPodSandboxes(client, opts) | ||
if err != nil { | ||
return fmt.Errorf("list pod sandboxes: %w", err) | ||
} | ||
r = getSandboxesList(r, opts) | ||
|
||
switch opts.output { | ||
case outputTypeJSON: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to deduplicate here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say no, because right now it behaves in the same way to output two images when doing something like: