@@ -506,6 +506,10 @@ var containerStatusCommand = &cli.Command{
506
506
Name : "name" ,
507
507
Usage : "Filter by container name regular expression pattern" ,
508
508
},
509
+ & cli.StringFlag {
510
+ Name : "namespace" ,
511
+ Usage : "Filter by pod namespace regular expression pattern" ,
512
+ },
509
513
& cli.StringFlag {
510
514
Name : "pod" ,
511
515
Aliases : []string {"p" },
@@ -545,12 +549,13 @@ var containerStatusCommand = &cli.Command{
545
549
546
550
if len (ids ) == 0 {
547
551
opts := & listOptions {
548
- nameRegexp : c .String ("name" ),
549
- podID : c .String ("pod" ),
550
- image : c .String ("image" ),
551
- state : c .String ("state" ),
552
- latest : c .Bool ("latest" ),
553
- last : c .Int ("last" ),
552
+ nameRegexp : c .String ("name" ),
553
+ podID : c .String ("pod" ),
554
+ podNamespaceRegexp : c .String ("namespace" ),
555
+ image : c .String ("image" ),
556
+ state : c .String ("state" ),
557
+ latest : c .Bool ("latest" ),
558
+ last : c .Int ("last" ),
554
559
}
555
560
opts .labels , err = parseLabelStringSlice (c .StringSlice ("label" ))
556
561
if err != nil {
@@ -656,6 +661,10 @@ var listContainersCommand = &cli.Command{
656
661
Aliases : []string {"r" },
657
662
Usage : "Show image path instead of image id" ,
658
663
},
664
+ & cli.StringFlag {
665
+ Name : "namespace" ,
666
+ Usage : "Filter by pod namespace regular expression pattern" ,
667
+ },
659
668
},
660
669
Action : func (c * cli.Context ) error {
661
670
if c .NArg () != 0 {
@@ -673,19 +682,20 @@ var listContainersCommand = &cli.Command{
673
682
}
674
683
675
684
opts := & listOptions {
676
- id : c .String ("id" ),
677
- podID : c .String ("pod" ),
678
- state : c .String ("state" ),
679
- verbose : c .Bool ("verbose" ),
680
- quiet : c .Bool ("quiet" ),
681
- output : c .String ("output" ),
682
- all : c .Bool ("all" ),
683
- nameRegexp : c .String ("name" ),
684
- latest : c .Bool ("latest" ),
685
- last : c .Int ("last" ),
686
- noTrunc : c .Bool ("no-trunc" ),
687
- image : c .String ("image" ),
688
- resolveImagePath : c .Bool ("resolve-image-path" ),
685
+ id : c .String ("id" ),
686
+ podID : c .String ("pod" ),
687
+ podNamespaceRegexp : c .String ("namespace" ),
688
+ state : c .String ("state" ),
689
+ verbose : c .Bool ("verbose" ),
690
+ quiet : c .Bool ("quiet" ),
691
+ output : c .String ("output" ),
692
+ all : c .Bool ("all" ),
693
+ nameRegexp : c .String ("name" ),
694
+ latest : c .Bool ("latest" ),
695
+ last : c .Int ("last" ),
696
+ noTrunc : c .Bool ("no-trunc" ),
697
+ image : c .String ("image" ),
698
+ resolveImagePath : c .Bool ("resolve-image-path" ),
689
699
}
690
700
opts .labels , err = parseLabelStringSlice (c .StringSlice ("label" ))
691
701
if err != nil {
@@ -1299,19 +1309,29 @@ func convertContainerState(state pb.ContainerState) string {
1299
1309
}
1300
1310
}
1301
1311
1302
- func getPodNameFromLabels (label map [string ]string ) string {
1303
- podName , ok := label [types .KubernetesPodNameLabel ]
1312
+ func getPodNameFromLabels (labels map [string ]string ) string {
1313
+ return getFromLabels (labels , types .KubernetesPodNameLabel )
1314
+ }
1315
+
1316
+ func getPodNamespaceFromLabels (labels map [string ]string ) string {
1317
+ return getFromLabels (labels , types .KubernetesPodNamespaceLabel )
1318
+ }
1319
+
1320
+ func getFromLabels (labels map [string ]string , label string ) string {
1321
+ value , ok := labels [label ]
1304
1322
if ok {
1305
- return podName
1323
+ return value
1306
1324
}
1307
1325
return "unknown"
1308
1326
}
1309
1327
1310
1328
func getContainersList (containersList []* pb.Container , opts * listOptions ) []* pb.Container {
1311
1329
filtered := []* pb.Container {}
1312
1330
for _ , c := range containersList {
1331
+ podNamespace := getPodNamespaceFromLabels (c .Labels )
1313
1332
// Filter by pod name/namespace regular expressions.
1314
- if matchesRegex (opts .nameRegexp , c .Metadata .Name ) {
1333
+ if matchesRegex (opts .nameRegexp , c .Metadata .Name ) &&
1334
+ matchesRegex (opts .podNamespaceRegexp , podNamespace ) {
1315
1335
filtered = append (filtered , c )
1316
1336
}
1317
1337
}
0 commit comments