Skip to content

Commit 2364268

Browse files
committed
Merge pull request #532 from vmarmol/fix
Sort subcontainers in ContainerSpec.
2 parents 4033f14 + 94cd711 commit 2364268

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

info/container.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ type ContainerReference struct {
7171
Namespace string `json:"namespace,omitempty"`
7272
}
7373

74+
// Sorts by container name.
75+
type ContainerReferenceSlice []ContainerReference
76+
77+
func (self ContainerReferenceSlice) Len() int { return len(self) }
78+
func (self ContainerReferenceSlice) Swap(i, j int) { self[i], self[j] = self[j], self[i] }
79+
func (self ContainerReferenceSlice) Less(i, j int) bool { return self[i].Name < self[j].Name }
80+
7481
// ContainerInfoQuery is used when users check a container info from the REST api.
7582
// It specifies how much data users want to get about a container
7683
type ContainerInfoRequest struct {

manager/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"flag"
1919
"fmt"
2020
"math"
21+
"sort"
2122
"sync"
2223
"time"
2324

@@ -321,6 +322,7 @@ func (c *containerData) updateStats() error {
321322
}
322323

323324
func (c *containerData) updateSubcontainers() error {
325+
var subcontainers info.ContainerReferenceSlice
324326
subcontainers, err := c.handler.ListContainers(container.ListSelf)
325327
if err != nil {
326328
// Ignore errors if the container is dead.
@@ -329,6 +331,7 @@ func (c *containerData) updateSubcontainers() error {
329331
}
330332
return err
331333
}
334+
sort.Sort(subcontainers)
332335
c.lock.Lock()
333336
defer c.lock.Unlock()
334337
c.info.Subcontainers = subcontainers

0 commit comments

Comments
 (0)