aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-22 12:21:53 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-22 18:12:57 +0000
commit34ba0cb8a922347364afaa14f199409ad7dc2451 (patch)
tree23fa7811dcf3de1501399f76373dc13bf4744d64 /libpod
parentbd4e106de3d890bd2b0520083c9ad7d314b61487 (diff)
downloadpodman-34ba0cb8a922347364afaa14f199409ad7dc2451.tar.gz
podman-34ba0cb8a922347364afaa14f199409ad7dc2451.tar.bz2
podman-34ba0cb8a922347364afaa14f199409ad7dc2451.zip
Order containers returned from state and make container config public
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #63 Approved by: baude
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go18
-rw-r--r--libpod/sql_state.go3
-rw-r--r--libpod/sql_state_internal.go2
-rw-r--r--libpod/sql_state_test.go13
4 files changed, 28 insertions, 8 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 9b48d2ca1..8ad0bb10d 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -46,7 +46,7 @@ const (
// Container is a single OCI container
type Container struct {
- config *containerConfig
+ config *ContainerConfig
pod *Pod
runningSpec *spec.Spec
@@ -59,7 +59,7 @@ type Container struct {
runtime *Runtime
}
-// containerState contains the current state of the container
+// containerRuntimeInfo contains the current state of the container
// It is stored on disk in a tmpfs and recreated on reboot
type containerRuntimeInfo struct {
// The current state of the running container
@@ -88,10 +88,10 @@ type containerRuntimeInfo struct {
// TODO: Save information about image used in container if one is used
}
-// containerConfig contains all information that was used to create the
+// ContainerConfig contains all information that was used to create the
// container. It may not be changed once created.
// It is stored, read-only, on disk
-type containerConfig struct {
+type ContainerConfig struct {
Spec *spec.Spec `json:"spec"`
ID string `json:"id"`
Name string `json:"name"`
@@ -153,6 +153,14 @@ func (c *Container) Labels() map[string]string {
return labels
}
+// Config returns the configuration used to create the container
+func (c *Container) Config() *ContainerConfig {
+ returnConfig := new(ContainerConfig)
+ deepcopier.Copy(c.config).To(returnConfig)
+
+ return returnConfig
+}
+
// LogPath returns the path to the container's log file
// This file will only be present after Init() is called to create the container
// in runc
@@ -235,7 +243,7 @@ func newContainer(rspec *spec.Spec) (*Container, error) {
}
ctr := new(Container)
- ctr.config = new(containerConfig)
+ ctr.config = new(ContainerConfig)
ctr.state = new(containerRuntimeInfo)
ctr.config.ID = stringid.GenerateNonCryptoID()
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index 893223914..8b18a8959 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -544,7 +544,8 @@ func (s *SQLState) AllContainers() ([]*Container, error) {
containerState.Pid
FROM containers
INNER JOIN
- containerState ON containers.Id = containerState.Id;`
+ containerState ON containers.Id = containerState.Id
+ ORDER BY containers.CreatedTime DESC;`
if !s.valid {
return nil, ErrDBClosed
diff --git a/libpod/sql_state_internal.go b/libpod/sql_state_internal.go
index b6816e008..58a6daa58 100644
--- a/libpod/sql_state_internal.go
+++ b/libpod/sql_state_internal.go
@@ -186,7 +186,7 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string) (*Contai
}
ctr := new(Container)
- ctr.config = new(containerConfig)
+ ctr.config = new(ContainerConfig)
ctr.state = new(containerRuntimeInfo)
ctr.config.ID = id
diff --git a/libpod/sql_state_test.go b/libpod/sql_state_test.go
index 5ccd069d3..9f6b5d078 100644
--- a/libpod/sql_state_test.go
+++ b/libpod/sql_state_test.go
@@ -15,7 +15,7 @@ import (
func getTestContainer(id, name string) *Container {
ctr := &Container{
- config: &containerConfig{
+ config: &ContainerConfig{
ID: id,
Name: name,
RootfsImageID: id,
@@ -518,4 +518,15 @@ func TestGetAllContainersTwoContainers(t *testing.T) {
ctrs, err := state.AllContainers()
assert.NoError(t, err)
assert.Equal(t, 2, len(ctrs))
+
+ // Containers should be ordered by creation time
+
+ // Use assert.EqualValues if the test fails to pretty print diff
+ // between actual and expected
+ if !testContainersEqual(testCtr2, ctrs[0]) {
+ assert.EqualValues(t, testCtr2, ctrs[0])
+ }
+ if !testContainersEqual(testCtr1, ctrs[1]) {
+ assert.EqualValues(t, testCtr1, ctrs[1])
+ }
}