@@ -486,7 +486,7 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
486
486
case "json" :
487
487
return outputProtobufObjAsJSON (r )
488
488
case "yaml" :
489
- return outputProtobufObjAsJSON (r )
489
+ return outputProtobufObjAsYAML (r )
490
490
case "table" , "" :
491
491
// continue; output will be generated after the switch block ends.
492
492
default :
@@ -498,14 +498,6 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
498
498
display .AddRow ([]string {columnPodID , columnCreated , columnState , columnName , columnNamespace , columnAttempt })
499
499
}
500
500
for _ , pod := range r .Items {
501
- // Filter by pod name/namespace regular expressions.
502
- if ! matchesRegex (opts .nameRegexp , pod .Metadata .Name ) {
503
- continue
504
- }
505
- if ! matchesRegex (opts .podNamespaceRegexp , pod .Metadata .Namespace ) {
506
- continue
507
- }
508
-
509
501
if opts .quiet {
510
502
fmt .Printf ("%s\n " , pod .Id )
511
503
continue
@@ -572,8 +564,17 @@ func convertPodState(state pb.PodSandboxState) string {
572
564
}
573
565
574
566
func getSandboxesList (sandboxesList []* pb.PodSandbox , opts listOptions ) []* pb.PodSandbox {
575
- sort .Sort (sandboxByCreated (sandboxesList ))
576
- n := len (sandboxesList )
567
+ filtered := []* pb.PodSandbox {}
568
+ for _ , p := range sandboxesList {
569
+ // Filter by pod name/namespace regular expressions.
570
+ if matchesRegex (opts .nameRegexp , p .Metadata .Name ) &&
571
+ matchesRegex (opts .podNamespaceRegexp , p .Metadata .Namespace ) {
572
+ filtered = append (filtered , p )
573
+ }
574
+ }
575
+
576
+ sort .Sort (sandboxByCreated (filtered ))
577
+ n := len (filtered )
577
578
if opts .latest {
578
579
n = 1
579
580
}
@@ -585,7 +586,7 @@ func getSandboxesList(sandboxesList []*pb.PodSandbox, opts listOptions) []*pb.Po
585
586
return a
586
587
}
587
588
return b
588
- }(n , len (sandboxesList ))
589
+ }(n , len (filtered ))
589
590
590
- return sandboxesList [:n ]
591
+ return filtered [:n ]
591
592
}
0 commit comments