From 94cd7114f82bd873ac701122c3a538f7466f4289 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Mon, 23 Feb 2015 14:28:02 -0800 Subject: [PATCH] Sort subcontainers in ContainerSpec. Fixes #531. --- info/container.go | 7 +++++++ manager/container.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/info/container.go b/info/container.go index b3816336..fde4033a 100644 --- a/info/container.go +++ b/info/container.go @@ -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 { diff --git a/manager/container.go b/manager/container.go index 53f746df..1c84acac 100644 --- a/manager/container.go +++ b/manager/container.go @@ -18,6 +18,7 @@ import ( "flag" "fmt" "math" + "sort" "sync" "time" @@ -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. @@ -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