sort all map type result in ocic
Signed-off-by: Crazykev <crazykev@zju.edu.cn>
This commit is contained in:
parent
018c4db06d
commit
295c32331a
2 changed files with 23 additions and 12 deletions
|
@ -453,14 +453,14 @@ func ListContainers(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
}
|
}
|
||||||
if c.Labels != nil {
|
if c.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
for k, v := range c.Labels {
|
for _, k := range getSortedKeys(c.Labels) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, c.Labels[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.Annotations != nil {
|
if c.Annotations != nil {
|
||||||
fmt.Println("Annotations:")
|
fmt.Println("Annotations:")
|
||||||
for k, v := range c.Annotations {
|
for _, k := range getSortedKeys(c.Annotations) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, c.Annotations[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -302,14 +303,14 @@ func PodSandboxStatus(client pb.RuntimeServiceClient, ID string) error {
|
||||||
}
|
}
|
||||||
if r.Status.Labels != nil {
|
if r.Status.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
for k, v := range r.Status.Labels {
|
for _, k := range getSortedKeys(r.Status.Labels) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, r.Status.Labels[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r.Status.Annotations != nil {
|
if r.Status.Annotations != nil {
|
||||||
fmt.Println("Annotations:")
|
fmt.Println("Annotations:")
|
||||||
for k, v := range r.Status.Annotations {
|
for _, k := range getSortedKeys(r.Status.Annotations) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, r.Status.Annotations[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -369,17 +370,27 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error {
|
||||||
fmt.Printf("Created: %v\n", ctm)
|
fmt.Printf("Created: %v\n", ctm)
|
||||||
if pod.Labels != nil {
|
if pod.Labels != nil {
|
||||||
fmt.Println("Labels:")
|
fmt.Println("Labels:")
|
||||||
for k, v := range pod.Labels {
|
for _, k := range getSortedKeys(pod.Labels) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, pod.Labels[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pod.Annotations != nil {
|
if pod.Annotations != nil {
|
||||||
fmt.Println("Annotations:")
|
fmt.Println("Annotations:")
|
||||||
for k, v := range pod.Annotations {
|
for _, k := range getSortedKeys(pod.Annotations) {
|
||||||
fmt.Printf("\t%s -> %s\n", k, v)
|
fmt.Printf("\t%s -> %s\n", k, pod.Annotations[k])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSortedKeys(m map[string]string) []string {
|
||||||
|
var keys []string
|
||||||
|
for k := range m {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue