Skip to content

Commit

Permalink
Sort subcontainers in ContainerSpec.
Browse files Browse the repository at this point in the history
Fixes google#531.
  • Loading branch information
vmarmol committed Feb 23, 2015
1 parent 1a3c40a commit 94cd711
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions info/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ type ContainerReference struct {
Namespace string `json:"namespace,omitempty"`
}

// Sorts by container name.
type ContainerReferenceSlice []ContainerReference

func (self ContainerReferenceSlice) Len() int { return len(self) }
func (self ContainerReferenceSlice) Swap(i, j int) { self[i], self[j] = self[j], self[i] }
func (self ContainerReferenceSlice) Less(i, j int) bool { return self[i].Name < self[j].Name }

// ContainerInfoQuery is used when users check a container info from the REST api.
// It specifies how much data users want to get about a container
type ContainerInfoRequest struct {
Expand Down
3 changes: 3 additions & 0 deletions manager/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"math"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -319,6 +320,7 @@ func (c *containerData) updateStats() error {
}

func (c *containerData) updateSubcontainers() error {
var subcontainers info.ContainerReferenceSlice
subcontainers, err := c.handler.ListContainers(container.ListSelf)
if err != nil {
// Ignore errors if the container is dead.
Expand All @@ -327,6 +329,7 @@ func (c *containerData) updateSubcontainers() error {
}
return err
}
sort.Sort(subcontainers)
c.lock.Lock()
defer c.lock.Unlock()
c.info.Subcontainers = subcontainers
Expand Down

0 comments on commit 94cd711

Please sign in to comment.