@@ -264,6 +264,11 @@ var listContainersCommand = cli.Command{
264
264
Value : "" ,
265
265
Usage : "Filter by container id" ,
266
266
},
267
+ cli.StringFlag {
268
+ Name : "name" ,
269
+ Value : "" ,
270
+ Usage : "filter by container name regular expression pattern" ,
271
+ },
267
272
cli.StringFlag {
268
273
Name : "pod, p" ,
269
274
Value : "" ,
@@ -310,16 +315,17 @@ var listContainersCommand = cli.Command{
310
315
}
311
316
312
317
opts := listOptions {
313
- id : context .String ("id" ),
314
- podID : context .String ("pod" ),
315
- state : context .String ("state" ),
316
- verbose : context .Bool ("verbose" ),
317
- quiet : context .Bool ("quiet" ),
318
- output : context .String ("output" ),
319
- all : context .Bool ("all" ),
320
- latest : context .Bool ("latest" ),
321
- last : context .Int ("last" ),
322
- noTrunc : context .Bool ("no-trunc" ),
318
+ id : context .String ("id" ),
319
+ podID : context .String ("pod" ),
320
+ state : context .String ("state" ),
321
+ verbose : context .Bool ("verbose" ),
322
+ quiet : context .Bool ("quiet" ),
323
+ output : context .String ("output" ),
324
+ all : context .Bool ("all" ),
325
+ nameRegexp : context .String ("name" ),
326
+ latest : context .Bool ("latest" ),
327
+ last : context .Int ("last" ),
328
+ noTrunc : context .Bool ("no-trunc" ),
323
329
}
324
330
opts .labels , err = parseLabelStringSlice (context .StringSlice ("label" ))
325
331
if err != nil {
@@ -617,6 +623,10 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
617
623
fmt .Fprintln (w , "CONTAINER ID\t IMAGE\t CREATED\t STATE\t NAME\t ATTEMPT\t POD ID" )
618
624
}
619
625
for _ , c := range r .Containers {
626
+ // Filter by pod name/namespace regular expressions.
627
+ if ! matchesRegex (opts .nameRegexp , c .Labels [kubeContainerNameLabel ]) {
628
+ continue
629
+ }
620
630
if opts .quiet {
621
631
fmt .Printf ("%s\n " , c .Id )
622
632
continue
0 commit comments