Use same state object for state and list
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
b1e602e8ba
commit
4350d90043
6
list.go
6
list.go
|
@ -22,6 +22,8 @@ const formatOptions = `table or json`
|
||||||
// containerState represents the platform agnostic pieces relating to a
|
// containerState represents the platform agnostic pieces relating to a
|
||||||
// running container's status and state
|
// running container's status and state
|
||||||
type containerState struct {
|
type containerState struct {
|
||||||
|
// Version is the OCI version for the container
|
||||||
|
Version string `json:"ociVersion"`
|
||||||
// ID is the container ID
|
// ID is the container ID
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
// InitProcessPid is the init process id in the parent namespace
|
// InitProcessPid is the init process id in the parent namespace
|
||||||
|
@ -30,6 +32,8 @@ type containerState struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
// Bundle is the path on the filesystem to the bundle
|
// Bundle is the path on the filesystem to the bundle
|
||||||
Bundle string `json:"bundle"`
|
Bundle string `json:"bundle"`
|
||||||
|
// Rootfs is a path to a directory containing the container's root filesystem.
|
||||||
|
Rootfs string `json:"rootfs"`
|
||||||
// Created is the unix timestamp for the creation time of the container in UTC
|
// Created is the unix timestamp for the creation time of the container in UTC
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
// Annotations is the user defined annotations added to the config.
|
// Annotations is the user defined annotations added to the config.
|
||||||
|
@ -140,10 +144,12 @@ func getContainers(context *cli.Context) ([]containerState, error) {
|
||||||
}
|
}
|
||||||
bundle, annotations := utils.Annotations(state.Config.Labels)
|
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||||
s = append(s, containerState{
|
s = append(s, containerState{
|
||||||
|
Version: state.BaseState.Config.Version,
|
||||||
ID: state.BaseState.ID,
|
ID: state.BaseState.ID,
|
||||||
InitProcessPid: pid,
|
InitProcessPid: pid,
|
||||||
Status: containerStatus.String(),
|
Status: containerStatus.String(),
|
||||||
Bundle: bundle,
|
Bundle: bundle,
|
||||||
|
Rootfs: state.BaseState.Config.Rootfs,
|
||||||
Created: state.BaseState.Created,
|
Created: state.BaseState.Created,
|
||||||
Annotations: annotations,
|
Annotations: annotations,
|
||||||
})
|
})
|
||||||
|
|
26
state.go
26
state.go
|
@ -5,36 +5,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/utils"
|
"github.com/opencontainers/runc/libcontainer/utils"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// cState represents the platform agnostic pieces relating to a running
|
|
||||||
// container's status and state. Note: The fields in this structure adhere to
|
|
||||||
// the opencontainers/runtime-spec/specs-go requirement for json fields that must be returned
|
|
||||||
// in a state command.
|
|
||||||
type cState struct {
|
|
||||||
// Version is the OCI version for the container
|
|
||||||
Version string `json:"ociVersion"`
|
|
||||||
// ID is the container ID
|
|
||||||
ID string `json:"id"`
|
|
||||||
// InitProcessPid is the init process id in the parent namespace
|
|
||||||
InitProcessPid int `json:"pid"`
|
|
||||||
// Bundle is the path on the filesystem to the bundle
|
|
||||||
Bundle string `json:"bundlePath"`
|
|
||||||
// Rootfs is a path to a directory containing the container's root filesystem.
|
|
||||||
Rootfs string `json:"rootfsPath"`
|
|
||||||
// Status is the current status of the container, running, paused, ...
|
|
||||||
Status string `json:"status"`
|
|
||||||
// Created is the unix timestamp for the creation time of the container in UTC
|
|
||||||
Created time.Time `json:"created"`
|
|
||||||
// Annotations is the user defined annotations added to the config.
|
|
||||||
Annotations map[string]string `json:"annotations,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var stateCommand = cli.Command{
|
var stateCommand = cli.Command{
|
||||||
Name: "state",
|
Name: "state",
|
||||||
Usage: "output the state of a container",
|
Usage: "output the state of a container",
|
||||||
|
@ -61,7 +37,7 @@ instance of a container.`,
|
||||||
pid = 0
|
pid = 0
|
||||||
}
|
}
|
||||||
bundle, annotations := utils.Annotations(state.Config.Labels)
|
bundle, annotations := utils.Annotations(state.Config.Labels)
|
||||||
cs := cState{
|
cs := containerState{
|
||||||
Version: state.BaseState.Config.Version,
|
Version: state.BaseState.Config.Version,
|
||||||
ID: state.BaseState.ID,
|
ID: state.BaseState.ID,
|
||||||
InitProcessPid: pid,
|
InitProcessPid: pid,
|
||||||
|
|
|
@ -47,7 +47,7 @@ function teardown() {
|
||||||
|
|
||||||
ROOT=$HELLO_BUNDLE runc list --format json
|
ROOT=$HELLO_BUNDLE runc list --format json
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[[ "${lines[0]}" == [\[][\{]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
||||||
[[ "${lines[0]}" == *[,][\{]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
|
||||||
[[ "${lines[0]}" == *[,][\{]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
|
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue